From MZXWiki
Jump to navigation Jump to search

A command is a single, executed line of Robotic in a given robot. In general, every line - including labels, comments, and even blank lines - is interpreted and treated as a command when they are encountered, save for some minor exceptions.

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 version 2.60 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, (1000000), 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 will 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 the average MZXer's Pentium II), 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.

Other than non cycle ending commands, there are cycle-ending and multi-cycle commands. Cycle ending commands, once executed, stop the processing of Robotic within the given robot. Usually any command that moves either the player or robot is cycle ending. Multi-cycle commands are unique in that they are executed over the course of 0 or more cycles before moving on to the next command. However, one downside to using multi-cycle commands is that if the robot is sent to a subroutine call by another robot, the command will be immediately interrupted to deal with the subroutine call, and on return the multi-cycle command will start over.