Difference between revisions of "Set.dir"

From AGI Wiki
Jump to navigationJump to search
(Created page with "set.dir   == <br />Syntax == <blockquote><code>set.dir(oA,vDIR);</code></blockquote> == <br />Description == The direction of object oA is changed ot vDIR. vDIR must...")
 
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
set.dir
+
The '''set.dir''' command sets the direction of motion for an object.
  
&nbsp;
+
== Syntax ==
  
== <br />Syntax ==
+
set.dir([[screen object|obj]] oA, [[variable|var]] vDIR);
  
<blockquote><code>set.dir(oA,vDIR);</code></blockquote>
+
== Remarks ==
  
== <br />Description ==
+
The direction of [[screen object]] '''oA''' is set to the value of [[variable]] '''vDIR''', which should be &gt;= 0 and &lt;= 8.
  
The direction of object oA is changed ot vDIR. vDIR must be between 0 and 8:
+
<blockquote>[[File:MovingObjects.png]]</blockquote>
  
[[File:MovingObjects.png]]
+
Changing the direction does not change the [[movement mode]]. For '''[[move.obj]]''', '''[[move.obj.v]]''' and '''[[follow.ego]]''' modes, changing direction with '''set.dir''' doesn't work, because AGI will automatically change direction back to keep the object moving toward its target.
  
 +
You cannot set the [[ego]] object's direction with the '''set.dir''' command, not even when it is in [[program.control|program control]] mode. To change ego's direction, you have to change the value of [[reserved variable]] [[v6  (ego direction)]].
  
You can not set the direction of ego (object 0). Instead, change the value of v6 to the direction you want.
+
== Possible Errors ==
  
To find out what direction an object is currently travelling in, use the get.dir command.
+
Using a '''vDIR''' value greater than 8 will cause AGI to [[crashing AGI|crash]] when the [[autoloop]] feature tries to set a [[loop]]. If the autoloop feature is disabled, direction values greater than 8 are still problematic, because AGI uses a lookup table to determine how to adjust the X and Y coordinates of an object based on direction; values greater than 8 exceed the table boundaries and use data meant for other purposes, resulting in unpredictable behavior in object motion.
  
== <br />Sources ==
+
AGI does not check that object number '''oA''' is a valid [[screen object]]. If it is not, this command will overwrite other data on the [[memory heap]], which may cause unexpected results, including possibly [[crashing AGI]].
  
[[AGI Studio Help File]]
+
== Example ==
  
== <br />See also ==
+
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="agi">
 +
v52 = 3;
 +
set.dir(o3, v52);  [ now object 3 will move to right
 +
</syntaxhighlight>
  
* <code>[[get.dir]]</code>
+
== Technical Information ==
* <code>[[start.motion]]</code>
 
* [[Moving Objects]]
 
  
&nbsp;
+
{| 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:'''
 +
| 86 (0x56 hex)
 +
|}
  
[[Category:Object Commands]]
+
== See Also ==
[[Category:View Commands]]
+
 
[[Category:References]]
+
'''[[follow.ego]]'''<br />
[[Category:Logic]]
+
'''[[get.dir]]'''<br />
 +
'''[[move.obj]]'''<br />
 +
'''[[move.obj.v]]'''<br />
 +
'''[[normal.motion]]'''<br />
 +
'''[[wander]]'''<br />
 +
[[Category:Commands]]<br />

Latest revision as of 22:48, 20 April 2019

The set.dir command sets the direction of motion for an object.

Syntax

set.dir(obj oA, var vDIR);

Remarks

The direction of screen object oA is set to the value of variable vDIR, which should be >= 0 and <= 8.

MovingObjects.png

Changing the direction does not change the movement mode. For move.obj, move.obj.v and follow.ego modes, changing direction with set.dir doesn't work, because AGI will automatically change direction back to keep the object moving toward its target.

You cannot set the ego object's direction with the set.dir command, not even when it is in program control mode. To change ego's direction, you have to change the value of reserved variable v6 (ego direction).

Possible Errors

Using a vDIR value greater than 8 will cause AGI to crash when the autoloop feature tries to set a loop. If the autoloop feature is disabled, direction values greater than 8 are still problematic, because AGI uses a lookup table to determine how to adjust the X and Y coordinates of an object based on direction; values greater than 8 exceed the table boundaries and use data meant for other purposes, resulting in unpredictable behavior in object motion.

AGI does not check that object number oA is a valid screen object. If it is not, this command will overwrite other data on the memory heap, which may cause unexpected results, including possibly crashing AGI.

Example

Code:

<syntaxhighlight lang="agi"> v52 = 3; set.dir(o3, v52); [ now object 3 will move to right </syntaxhighlight>

Technical Information

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

See Also

follow.ego
get.dir
move.obj
move.obj.v
normal.motion
wander