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

[Lua][Help] A counter that sets off a redstone pulse after 10 counts.

Started by Drsirdeath, 12 July 2012 - 03:41 PM
Drsirdeath #1
Posted 12 July 2012 - 05:41 PM
I made a redstone counter but i want it to excute a function after 10 counts.

after 10 coutns i want the computer to send off a signal to the left. Heres what i have so far:

local monitor = peripheral.wrap("right")
monitor.setTextScale(5)
term.redirect(peripheral.wrap("right"))
localcount = 0
local lastInput = rs.getInput("back")

while true do
term.clear()
term.setCursorPos(1, 1)
print(count)
os.pullEvent("redstone")
local input = rs.getInput("back")
if input ~= lastInput then
if input then
count = count + 1
when
count = 10
redstone.setOutput("left", true)
else
count = 11
redstone.setOutput("left", false)
end
lastInput = input
end
end



Note: This is not my script i got it from searching through other threads. Also i am very noobish and probably ruined it just by adding

when
count = 10
redstone.setOutput("left", true)
else
count = 11
redstone.setOutput("left", false)

Please help i am terrible at this
OmegaVest #2
Posted 12 July 2012 - 05:57 PM
Okay, so when is not a command. If is.

So, the code segment you want is:


if count == 10 then
   redstone.setOutput("left", true)
elseif count == 11 then
   redstone.setOutput("left", false)



Also, for comparing values, you need to use two ='s. Go take a look at some of the tutorials. They might help you a bit more.
Drsirdeath #3
Posted 12 July 2012 - 06:36 PM
Alright but now i get the error

bios:206: [string"Game"]:26: 'end' expected (to close 'if')
OmegaVest #4
Posted 12 July 2012 - 07:17 PM
Ah, yeah forgot a line. Add a line with the word "end" just below the previous section.
Revenant Wendigo #5
Posted 13 July 2012 - 02:51 AM
Like OmegaVest mentioned, always make sure when you want something to check if it's = to something use == not =. When you use one = that is saying count is equal to 10.