Go: Difference between revisions

From Wiki of ZZT
Jump to navigation Jump to search
(use of #go in #if statements; #go idle infinite loop bug (credit to asie for debugging this when I ran into it))
m (code -> instruction)
Line 10: Line 10:


== #go idle quirk ==
== #go idle quirk ==
If an object is commanded to <code>#go idle</code> (or <code>#go i</code>) instead of <code>/idle</code> or <code>/i</code>, it will become trapped in an infinite loop, unable to progress the code pointer to the next command. If this command results from an [[if]] statement that is true (e.g. <code>#if [[alligned]] go idle</code>), it will not proceed any further in its code until the [[flag]] in the statement is false. This is because the code for the <code>/</code> shortcut contains a check for whether the object's change in X and Y positions are both 0 (i.e. if it is <code>idle</code>) before attempting to move, but the code for <code>#go</code> does not. As a result, any object that uses a <code>#go idle</code> command will detect a non-walkable tile at ''its own location'', attempt to push itself to no avail, and then assume it is blocked by an obstacle, pausing execution.
If an object is commanded to <code>#go idle</code> (or <code>#go i</code>) instead of <code>/idle</code> or <code>/i</code>, it will become trapped in an infinite loop, unable to progress the instruction pointer to the next command. If this command results from an [[if]] statement that is true (e.g. <code>#if [[alligned]] go idle</code>), it will not proceed any further in its code until the [[flag]] in the statement is false. This is because the code for the <code>/</code> shortcut contains a check for whether the object's change in X and Y positions are both 0 (i.e. if it is <code>idle</code>) before attempting to move, but the code for <code>#go</code> does not. As a result, any object that uses a <code>#go idle</code> command will detect a non-walkable tile at ''its own location'', attempt to push itself to no avail, and then assume it is blocked by an obstacle, pausing execution.


{{ZZT-OOP navbox}}
{{ZZT-OOP navbox}}

Revision as of 20:19, 24 August 2021

#go (Shortened: /) is a ZZT-OOP movement command which makes an object move one step. If the destination is blocked by an obstacle, the object will wait until the path is clear before stepping into the spot and continuing on with program execution.

If a #go statement is used at the end of an #if statement (e.g. #if contact go <direction>) and the object is obstructed in that direction, it will wait until either the obstacle is cleared away or the flag in the statement is false. In the latter case, the object will stop its attempt to move and skip to the next command.

Syntax

Full form: #go <direction>

Shortened form: /<direction>

#go idle quirk

If an object is commanded to #go idle (or #go i) instead of /idle or /i, it will become trapped in an infinite loop, unable to progress the instruction pointer to the next command. If this command results from an if statement that is true (e.g. #if alligned go idle), it will not proceed any further in its code until the flag in the statement is false. This is because the code for the / shortcut contains a check for whether the object's change in X and Y positions are both 0 (i.e. if it is idle) before attempting to move, but the code for #go does not. As a result, any object that uses a #go idle command will detect a non-walkable tile at its own location, attempt to push itself to no avail, and then assume it is blocked by an obstacle, pausing execution.