Difference between revisions of "Set.dir"

From AGI Wiki
Jump to navigationJump to search
 
Line 1: Line 1:
set.dir
+
The '''set.dir''' command sets the direction of motion for an object.
  
 
+
== 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>
 +
 
 +
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)]].
  
<blockquote>[[File:MovingObjects.png]]</blockquote>
+
== Possible Errors ==
  
You can not set the direction of ego (object 0). Instead, change the value of v6 to the direction you want.
+
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.
  
To find out what direction an object is currently traveling in, use the <code>[[get.dir]]</code> command.
+
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]].
  
== <br />Sources ==
+
== Example ==
  
[[AGI Studio Help File]]
+
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="agi">
 +
v52 = 3;
 +
set.dir(o3, v52);  [ now object 3 will move to right
 +
</syntaxhighlight>
  
== <br />See also ==
+
== Technical Information ==
  
* <code>[[get.dir]]</code>
+
{| border="1" cellpadding="2"
* <code>[[start.motion]]</code>
+
| style="background-color: #efefef" width="200" | '''Required Interpreter Version:'''
* [[Moving Objects]]
+
| width="175" | Available in all AGI versions.
 +
|-
 +
| style="background-color: #efefef" | '''Byte-Code Value:'''
 +
| 86 (0x56 hex)
 +
|}
  
&nbsp;
+
== See Also ==
  
[[Category:Object Commands]]
+
'''[[follow.ego]]'''<br />
[[Category:View Commands]]
+
'''[[get.dir]]'''<br />
[[Category:References]]
+
'''[[move.obj]]'''<br />
[[Category:Logic]]
+
'''[[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:
v52 = 3;
set.dir(o3, v52);  [ now object 3 will move to right

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