Move.obj
The move.obj command sets an object's movement mode to 'move object', meaning it will move toward a specified screen coordinate.
Syntax
move.obj(obj oA, byt X, byt Y, byt STEP, flg fDONE);
Remarks
Screen object oA begins moving toward the point (X, Y). AGI calculates the best direction based on distance from the point. The screen object will move STEP pixels each step. If STEP is zero, the screen object's current step size is used. When the screen object is less than STEP pixels away from point (X, Y), the screen object's direction is set to 0, flag fDONE is set to TRUE, and the screen object switches to normal motion. The screen object's original step size is restored.
Flag fDONE is reset to FALSE when the command is executed.
Setting the movement mode to 'move object' will automatically enable the screen object for updating if not currently enabled. The cycling property is not modified by the move.obj command.
If oA is ego, it automatically switches to program control mode. It also returns to player control mode automatically when it reaches its target location.
If you use the set.dir command when a screen object's motion is set to move to a point, the screen object will move in that direction for one interpreter cycle, but will begin moving toward the end point again after that.
Possible Errors
AGI does not check that object number oA is a valid object. If it is not, this command will overwrite other data on the memory heap, which may cause unexpected results, including possibly crashing AGI.
If either X or Y are off screen (X >= 160; Y >= 168), the command behaves a bit differently. As soon as the object reaches an edge, AGI will set flag fDONE to TRUE, and switch the object to normal motion, but the object's direction is not set to zero. If the object was moving diagonally when it touched the edge, it will continue moving along the edge since its direction was not set to zero. To avoid unintentional results, it is best to avoid using invalid values for X and Y.
WARNING: If your game relies on the flag fDONE to be set before continuing with something, such as going to the next part of a cut scene, make sure that the object will always be able to reach its destination. It is possible that it could get caught behind a barrier or something, and not be able to get where it needs to go, in which case the game will sit there forever doing nothing. This is more of a problem when the object being moved is ego - it might work fine from where you test it, but it may be possible for the player to move ego into such a position where they will get “stuck” when being moved.
Example
<syntaxhighlight lang="agi">move.obj(o1, 120, 44, 2, f99); [ object will move to the point (120, 44), [ two pixels per step </syntaxhighlight>
Technical Information
Required Interpreter Version: | Available in all AGI versions. |
Byte-Code Value: | 81 (0x51 hex) |