Busyloop

From MZXWiki
Revision as of 23:53, 29 January 2009 by Wervyn (talk | contribs) (New, short explanation of busyloops)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In MegaZeux parlance, a busyloop is any program loop designed to execute continuously during the game, such as:

: "loop"
. "do some code here"
goto "loop"

More specifically, this term often refers to a loop like the previous one that does not have an explicit cycle terminator, and thus does more work than it should per cycle. In the past this wasn't a big deal and had few negative effects, since the commands-per-cycle limit of 40 forced execution to move to the next robot fairly quickly. Since the addition of the "commands" counter, which can variably set this number into the billions, a loop like this becomes a far more serious problem, and can easily cause a game to hang. For this reason, it is recommended that all busyloops contain the command "cycle 1" at some point in their execution. Usually the best place is right after the loop label, if there are multiple points of return; or right before the "goto" command if there is only one.