Commands

From MZXWiki
Revision as of 21:14, 29 January 2009 by Terryn (talk | contribs)
Jump to navigation Jump to search

A command is a single, executed line of Robotic in a given robot. There are some minor exceptions that affect whether a line is actually executed and counts as a command. But in general, all lines - including labels, comments, and even blank lines - count as commands when they are encountered.

This is important because each robot in a Megazeux world is allowed to execute a certain number of commands per cycle, before control automatically passes to the next robot on the board. Historically, this number has been 40 since MZX version 2.00 (25 before that), but since the port Megazeux has provided the aptly named "commands" counter to set this number to something else. In games with complex engines requiring a lot of computation, it is common to see this counter set to something high, in order allow the engine function in a reasonable amount of time. Popular settings include 1000, 32767, and the expression (-1>>1) that sets the value as high as possible.

However it is worth cautioning that while "commands" sets a software limit on what MZX is allowed to do, you can still come up against a hardware limit on what MZX is able to do. At a certain point (2^16 = 65536 average total commands per cycle on a reasonably fast computer), attempting to actually execute as many commands as you're allowed to will start causing noticeably slow performance. This can become much more pronounced for processor intensive commands like copy block, which take more time to execute, to the point where MZX hangs and becomes completely unusable. Therefore, while it is usually recommended to set "commands" much higher than you actually need, it is also strongly recommended that you make sure each robot only executes as many commands as it needs to per cycle, particularly when loops are involved. When an engine incorporates a main program loop that is supposed to execute each cycle make sure the loop explicitly terminates with a cycle-ending command like cycle 1.