7 posts
Location
North Carolina
Posted 22 June 2012 - 11:16 PM
this is my code
print "how many items"
local i = tonumber(read())
counter = 0
while counter ~= i do
counter = counter + 1
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
end
this program is meant to despent the number of items you specify. but it wont work and i dont know why.
7 posts
Location
North Carolina
Posted 22 June 2012 - 11:21 PM
and when i run this program the redstone stays on and the loop dosent end like its sopose too
65 posts
Location
The Internet
Posted 22 June 2012 - 11:27 PM
perhaps try this…
print "how many items"
local i = read()
i = tonumber(i)
counter = 0
while counter ~= i do
counter = counter + 1
rs.setOutput("right",true)
sleep(1)
rs.setOutput("right",false)
end
11 posts
Location
Belgium
Posted 22 June 2012 - 11:32 PM
You need to sleep after turning off the output as well, otherwise it gets immediately turned on again in the next iteration.
while counter ~= i do
counter = counter + 1
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
sleep(1)
end
65 posts
Location
The Internet
Posted 22 June 2012 - 11:34 PM
You need to sleep after turning off the output as well, otherwise it gets immediately turned on again in the next iteration.
while counter ~= i do
counter = counter + 1
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
sleep(1)
end
hmm, quite disappointed in myself for missing this.
7 posts
Location
North Carolina
Posted 22 June 2012 - 11:35 PM
it works thank you
1548 posts
Location
That dark shadow under your bed...
Posted 23 June 2012 - 09:46 PM
why does everyone do the long way around for a simple loop? sorry I just don't see any advantages in it. why not just
for i=1,tonumber(count) do
end
is there any problems with this method?
1604 posts
Posted 23 June 2012 - 09:52 PM
why does everyone do the long way around for a simple loop? sorry I just don't see any advantages in it. why not just
for i=1,tonumber(count) do
end
is there any problems with this method?
No, it's just that some people understands better that way. The for loop is pretty easy, but can be confusing when learning.