Alright guys, I'm trying to get a clearArea program running, but much to my demise, the very end of the program has some random call to my continue() function though the condition to run it should be false (actually in the command stream, it should not even be checking it again at all). It runs as usual, properly performs the X while statement in init() by executing continue at proper times, but at the end of the while statement, continue gets called again....somehow. Ideas?
http://pastebin.com/vHJbJ8qF
If you put a 2x2 blockset in front of the turtle with him in the far left corner and use clearArea, he will properly mine them (and any dimensions if you change width and length), the issue occurs when
he gets to the end of the loop, instead of sitting there and waiting, he calls continue() which essentially makes him appear to flip out at the end of the loop. Why is it getting called?
Uncalled function running randomly
Started by Noiro, Jun 19 2013 09:44 PM
4 replies to this topic
#1
Posted 19 June 2013 - 09:44 PM
#2
Posted 19 June 2013 - 10:21 PM
Try initializing x as 1 instead of 0, same with y.
#3
Posted 19 June 2013 - 10:27 PM
To your "demise"? That's quite a bug you've got there... 
To my eye, starting "x" at 1 will result in one too few lines being dug. But, you have got it rigged so that for every "line" call there's one "continue" call, and I'd say that's your problem: you want one less "continue", much the same as you've rigged one less "digUp".
Also, consider trying "for" loops. This:
... can be re-written as this:
The result is much the same: "x" starts at 0 and increments by 1 with each loop. The loop stops when "x" would exceed "width-1".
To my eye, starting "x" at 1 will result in one too few lines being dug. But, you have got it rigged so that for every "line" call there's one "continue" call, and I'd say that's your problem: you want one less "continue", much the same as you've rigged one less "digUp".
Also, consider trying "for" loops. This:
x = 0
while x ~= width do
-- etc
x=x+1
end
... can be re-written as this:
for x=0,width-1 do
-- etc
end
The result is much the same: "x" starts at 0 and increments by 1 with each loop. The loop stops when "x" would exceed "width-1".
#4
Posted 19 June 2013 - 10:32 PM
Lyqyd, on 19 June 2013 - 10:21 PM, said:
Try initializing x as 1 instead of 0, same with y.
Bomb Bloke, on 19 June 2013 - 10:27 PM, said:
To your "demise"? That's quite a bug you've got there... 
To my eye, starting "x" at 1 will result in one too few lines being dug. But, you have got it rigged so that for every "line" call there's one "continue" call, and I'd say that's your problem. You want one less "continue", much the same as you've rigged one less "digUp".
Also, consider trying "for" loops. This:
... can be re-written as this:
The result is much the same: "x" starts at 0 and increments by 1 with each loop. The loop stops when "x" would exceed "width-1".
To my eye, starting "x" at 1 will result in one too few lines being dug. But, you have got it rigged so that for every "line" call there's one "continue" call, and I'd say that's your problem. You want one less "continue", much the same as you've rigged one less "digUp".
Also, consider trying "for" loops. This:
x = 0 while x ~= width do -- etc x=x+1 end
... can be re-written as this:
for x=0,width-1 do -- etc end
The result is much the same: "x" starts at 0 and increments by 1 with each loop. The loop stops when "x" would exceed "width-1".
That worked like a charm (adding an 'if' in there). I can't believe I missed that. And the issue with for loops is that a for loop will always run at least once regardless of if the condition matches or not whereas a while loop will not run unless the condition is met (Well...that's what I remember anyway, could be wrong).
#5
Posted 19 June 2013 - 10:58 PM
No, "for" loops don't have that problem. Try this out to see:
Because "x" starts out exceeding 0, the loop never executes and the print statement is skipped entirely.
for x=1,0 do print("Blah") end
Because "x" starts out exceeding 0, the loop never executes and the print statement is skipped entirely.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











