Difference between revisions of "Move.obj"

From AGI Wiki
Jump to navigationJump to search
Line 1: Line 1:
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 ==
  
== <br />Syntax ==
+
move.obj([[screen object|obj]] oA, [[number|byt]] X, [[number|byt]] Y, [[number|byt]] STEP, [[flag|flg]] fDONE);
  
<blockquote><code>move.obj(oA,X,Y,STEPSIZE,fDONEFLAG);</code></blockquote>
+
== Remarks ==
  
== <br />Description ==
+
[[Screen object]] '''oA''' begins moving toward the point ('''X''', '''Y'''). AGI calculates the best direction based on distance from the point. The object will move '''STEP''' pixels each step. If '''STEP''' is zero, the object's current [[step size]] is used. When the object is less than '''STEP''' pixels away from point ('''X''', '''Y'''), the object's direction is set to 0, flag '''fDONE''' is set to TRUE, and the object switches to normal motion. The object's original step size is restored.
  
Object oA moves from it’s current location to X,Y by STEPSIZE pixels every step. fDONEFLAG is reset when the command is issued, and set when the object reaches it’s destination. If STEPSIZE is 0, the current step size of object oA is used. If object oA is ego (object 0), the interpreter executes the <code>[[program.control]]</code> command.
+
Flag '''fDONE''' is reset to FALSE when the command is executed.
  
Warning: If your program is relying on the flag fDONEFLAG to be set before continuing with something, such as going to the next part of a cutscene, make sure that the object will always be able to reach it’s 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 might 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.
+
Setting the movement mode to 'move object' will automatically enable the object for [[updating]] if not currently enabled. The [[cycling property]] is not modified by the '''move.obj''' command.
  
== <br />Sources ==
+
If '''oA''' is [[ego]], it automatically switches to [[program.control|program control mode]]. It also returns to [[player.control|player control mode]] automatically when it reaches its target location.
  
[[AGI Studio Help File]]
+
If you use the '''[[set.dir]]''' command when an object's motion is set to move to a point, the object will move in that direction for one [[interpreter cycle]], but will begin moving toward the end point again after that.
  
== <br />See also ==
+
== Possible Errors ==
  
* <code>[[move.obj.v]]</code>
+
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]].
* <code>[[step.size]]</code>
 
* <code>[[normal.motion]]</code>
 
* <code>[[Moving Objects]]</code>
 
  
&nbsp;
+
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'''.
  
[[Category:Object Commands]]
+
'''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.
[[Category:View Commands]]
+
 
[[Category:References]]
+
== Example ==
[[Category:Logic]]
+
 
 +
<div class="CodeBlockHeader">Code:</div>
 +
<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 ==
 +
 
 +
{| border="1" cellpadding="2"
 +
| style="background-color: #efefef" width="200" | '''Required Interpreter Version:'''
 +
| width="175" | Available in all AGI versions.
 +
|-
 +
| style="background-color: #efefef" | '''Byte-Code Value:'''
 +
| 81 (0x51 hex)
 +
|}
 +
 
 +
== See Also ==
 +
 
 +
'''[[move.obj.v]]'''<br />
 +
'''[[set.dir]]'''<br />
 +
[[Category:Commands]]<br />

Revision as of 15:03, 11 April 2019

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 object will move STEP pixels each step. If STEP is zero, the object's current step size is used. When the object is less than STEP pixels away from point (X, Y), the object's direction is set to 0, flag fDONE is set to TRUE, and the object switches to normal motion. The 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 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 an object's motion is set to move to a point, the 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

Code:
move.obj(o1, 120, 44, 2, f99);
[ object will move to the point (120, 44), 
[ two pixels per step

Technical Information

Required Interpreter Version: Available in all AGI versions.
Byte-Code Value: 81 (0x51 hex)

See Also

move.obj.v
set.dir