This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
crazybannanamon's profile picture

Can't get this working

Started by crazybannanamon, 08 August 2012 - 03:15 AM
crazybannanamon #1
Posted 08 August 2012 - 05:15 AM
I'm trying to make a simple redstone pulse counter that displays the count on a monitor. I'm a newbie to lua so
whats wrong with it?

output = 0

if rs.getInput("back",true) then
output = output + 1
mon.clear()
mon.write(output)
end
Luanub #2
Posted 08 August 2012 - 06:14 AM
rs.getInput() does not require a boolean. Also the mon. function will not work unless you have your own mon API with those functions in it. See comments below.


local output = 0 -- better to use local vars, less problematic

is rs.getInput("back") then
output = output + 1
term.clear()  -- mon.clear() wont work unless you've made your own API called mon with a clear function. The next two lines will clear screen and move cursor back to the top
term.setCursorPos(1,1)
write(output) -- same thing with the mon here, just use write() or print()
end
ardera #3
Posted 08 August 2012 - 07:01 AM
@luanub: Im not shure but can it be that mon is for monitor? then he forgot the peripheral.wrap
Luanub #4
Posted 08 August 2012 - 07:26 AM
@luanub: Im not shure but can it be that mon is for monitor? then he forgot the peripheral.wrap

Ya that is possible that it is a var for the monitor and that we are not seeing all of the code. If that is the case then it should be fine the way it was originally.
KaoS #5
Posted 08 August 2012 - 07:42 AM
don't forget to loop it, enclose all of that in a loop with a sleep(0.5) or it will just check once and end

you could also use os.pullEvent() instead of sleep(0.5) as it will return something every time the redstone input changes