print("Enter #")
a = read()
i = 0
while a>i do
rs.setBundledOutput("right", colors.green)
sleep(2)
print("done")
rs.setBundledOutput("right", colors.red)
sleep(0.2)
i = i+1
end
While loop problem
Started by Mr0reo, Jan 21 2013 12:05 PM
3 replies to this topic
#1
Posted 21 January 2013 - 12:05 PM
I am trying to make a simple code that will take a number from the user and pulse a redstone signal that many times. But when I run it it says "Attempt to compare string with number expected, got string". my question is why does it think that I am inputting a string, and how do I fix it?
#2
Posted 21 January 2013 - 12:10 PM
print("Enter #")
a = tonumber(read())
i = 0
while a > i do
rs.setBundledOutput("right", colors.green)
sleep(2)
print("done")
rs.setBundledOutput("right", colors.red)
sleep(0.2)
i = i+1
end
Maybe this?
#3
Posted 21 January 2013 - 12:10 PM
read() outputs a string. do "a = tonumber(a)" after the the read to convert it. For the way you're using the loop a numerical for loop would be a better option. It will do the incrementing for you an eliminate the need for i.
print("Enter #")
a = read()
for i=1, tonumber(a) do
rs.setBundledOutput("right", colors.green)
sleep(2)
print("done")
rs.setBundledOutput("right", colors.red)
sleep(0.2)
end
#4
Posted 21 January 2013 - 12:13 PM
Thanks for the help it worked
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











