Posted 01 October 2012 - 09:34 AM
Just picked up computer craft a few hours ago and figured out how to write on monitors, as that was my original purpose.
However, I found myself wanting to do more with it as its just too cool.
I searched the forums and found some programs and guidelines that would count redstone pulses from block detectors and display it like:
"1 cobblestone"
and each subsequent pulse would add a line under that as:
"2 cobblestone"
etc
While that's awesome, I want some static text on the monitor while just having a number value change on it.
For example a line I want to come up:
" Cobblestone [0/75]"
With the 0 counting up as that computer receives redstone signals. So after one cobblestone goes through, the same line rewrites itself to:
"Cobblestone [1/75]"
Using my limited knowledge, the program I came up with is:
local count = 0
local lastInput = false
while true do
term.setCursorPos(1,1)
write("Cobblestone [0/75]")
os.pullEvent("redstone")
local input = rs.getinput("<side redstone is coming from>")
if input ~= lastInput then
if input then
count = count + 1
term.clear()
term.setCursorPos(1,1)
write("Cobblestone ["..count"/75]")
end
end
end
When I run it though, an 11 comes up on my screen… so I'm failing pretty hard core at this and could use some help.
However, I found myself wanting to do more with it as its just too cool.
I searched the forums and found some programs and guidelines that would count redstone pulses from block detectors and display it like:
"1 cobblestone"
and each subsequent pulse would add a line under that as:
"2 cobblestone"
etc
While that's awesome, I want some static text on the monitor while just having a number value change on it.
For example a line I want to come up:
" Cobblestone [0/75]"
With the 0 counting up as that computer receives redstone signals. So after one cobblestone goes through, the same line rewrites itself to:
"Cobblestone [1/75]"
Using my limited knowledge, the program I came up with is:
local count = 0
local lastInput = false
while true do
term.setCursorPos(1,1)
write("Cobblestone [0/75]")
os.pullEvent("redstone")
local input = rs.getinput("<side redstone is coming from>")
if input ~= lastInput then
if input then
count = count + 1
term.clear()
term.setCursorPos(1,1)
write("Cobblestone ["..count"/75]")
end
end
end
When I run it though, an 11 comes up on my screen… so I'm failing pretty hard core at this and could use some help.