Request Computer Craft Counter

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord
D

Disco Turtle

Guest
Hey, first time using computer craft and was wanting to create a "Kill counter" like thing

I wasn't going to have it actually count kills, but rather increase in number every couple of seconds, such as +5 every three seconds.


Anybody know a simple program for computer craft that could show this increasing number on a monitor?

It's a silly request, ik, ty for any help
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
Here is a simple program that sort of does what you want. (assuming it works, as I haven't tested it)

Code:
local sleepTime = 3
local toAdd = 5

local i = 0
while true do
    print(i)
    sleep(sleepTime)
    i = i + toAdd
end
This will just write the number to a new line on the screen itself. Luckily you can change that using the monitor command http://www.computercraft.info/wiki/Monitor
If the monitor is placed on the top that should thus be
Code:
monitor top {name of this script}
Note that this counter will reset if the chunk gets unloaded as the computer will shutdown.

So.... some way to improve this would be to use the file api to store the number and read it on startup and write to it every time the number changes.https://www.lua.org/pil/21.2.html
Read on how to work with files here: https://www.lua.org/pil/21.2.html
Also, making use of the term api instead of the print function would improve it. That way you can have the number at a fixed place http://www.computercraft.info/wiki/index.php?title=Term_(API)&redirect=no
Combined with using the monitor directly from withing the code would probably also be nice. This would allow you to name it startup to automatically start it if the computer boots up.

I'm currently not really in a position to add all those things as frankly its way too late right now and I'm not going to start minecraft just to make sure it would run. Hopefully though this script together with the provided links and pointers to improve the script are a nice start :) .
 
D

Disco Turtle

Guest
Thanks a shit ton man, i'll test it out, and take a look at the links you sent me.

Thanks