Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm working on a code for clearing the waypoint course
#4
Programs always execute in order from top to bottom (with the exception of loops etc.). It goes more like this: "Look for a WayPoint and store it under the name item. If the item was not found, stop looking. Otherwise, go to the item and then return to the beginning of the program. After you're done with the WayPoints, turn 90 degrees left and move 20 meters forward."

With the if after goto, it goes like this:
"Look for a WayPoint and store it under the name item. Go to the item. (You didn't check if the 'item' is found yet, it may not even exist! Trying to go to something that does not exist would cause an error) If the item was not found, stop looking, otherwise, return to the beginning of the program. After you're done with the WayPoints, turn 90 degrees left and move 20 meters forward."

If you translate exactly what you said into code, it looks something like this (note that I used some weird construct in while() to keep it looking exactly like you said):
Code:
object item;
while((item = radar(WayPoint)) != null) {
    goto(item.position);
    // no need for any if(false) - while statement ends automatically if the condition is not true at the end of the loop
}
turn(90);
move(20);
and this should work as well


Messages In This Thread
RE: I'm working on a code for clearing the waypoint course - by krzys_h - 07-21-2018, 12:17 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)