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

[Error][LUA] Running command X amount of times

Started by ccsoxos, 14 September 2012 - 06:37 PM
ccsoxos #1
Posted 14 September 2012 - 08:37 PM
i want my computer to run a deployer and a block breaker form redpower x amount of times but i keep getting an error in line 16 it exspect "then" but its already there


local T
local Times
term.write("How many times shall it run: ")
T = read()
write("okay "..T)
write(" times")
while true do
redstone.setOutput("right", true)
sleep(0.5)
redstone.setOutput("right", false)
sleep(0.5)
redstone.setOutput("left", true)
sleep(0.5)
redstone.setOutput("left", false)
Times = Times+1
if Times = T then
break
end
print("Jobs done")
sjele #2
Posted 14 September 2012 - 08:49 PM

if Times == T then
That should be line 16.

= means you are setting a var
== means you are comparing a var
Cranium #3
Posted 14 September 2012 - 08:53 PM
You can shorten this with a "for" loop.

print("How many times do you want this to run?")
write("Number: ")
local number = read()
print("Okay. This will run "..number.." times.")
for i = 1,tonumber(number) do
rs.setOutput("right",true)
sleep(.5)
rs.setOutput("right",false)
sleep(.5)
rs.setOutput("left",true)
sleep(.5)
rs.setOutput("left",false)
end
print("Complete")
ccsoxos #4
Posted 14 September 2012 - 08:55 PM
thanks both of you
using it for frame quarry up and down arm