Difference between revisions of "Follow.ego"

From AGI Wiki
Jump to navigationJump to search
 
Line 1: Line 1:
== follow.ego ==
+
The '''follow.ego''' command sets a [[screen object|screen object's]] [[movement mode]] to ‘follow ego’, meaning it will always move toward the [[ego]] object (o0).
  
The '''follow.ego''' command sets an object's motion style to move toward the ego object (o0).
+
== Syntax ==
[edit]
 
Syntax
 
  
<blockquote>
+
follow.ego([[screen object|obj]] oA, [[number|byt]] DISTANCE, [[flag|flg]] fCAUGHT);
follow.ego([[Animated Object|obj]] oA, [[Number|byt]] STEP, [[Flag|flg]] fDONE);
 
</blockquote>
 
  
=== Remarks ===
+
== Remarks ==
  
<blockquote>
+
Object '''oA''' begins moving toward [[ego]]. AGI calculates the direction to move based on distance from ego. If an [[obstacle]] is encountered, AGI will move in a random direction for a few [[interpreter cycles]] before trying again to follow ego. The number of cycles that it will move before trying again is the greater of the distance to ego or the object's current step size.
Object oA begins moving toward ego. The interpreter calculates the best direction based on distance from ego, and any obstacles it encounters.  
 
  
Flag fDONE is reset when the command is executed.  
+
Setting the movement mode to &lsquo;follow ego&rsquo; will automatically enable the object for [[updating]] if not currently enabled. The [[cycling property]] is not modified by the '''follow.ego''' command.
  
The object will move STEP pixels each step (or it will move at its current step size, if STEP is less than the object's step size).  
+
Flag '''fCAUGHT''' is reset to FALSE when the command is executed.
  
When it is within STEP pixels of ego's position, the object will stop moving, flag fDONE is set, and the object switches to normal motion style.  
+
If '''DISTANCE''' is zero (0), AGI uses object '''oA'''&rsquo;s current [[step size]] as the DISTANCE value. When '''oA''' is within DISTANCE pixels of ego's position, the object will stop moving, flag '''fCAUGHT''' is set, and the object switches to &lsquo;normal&rsquo; [[movement mode]].
  
The [[set.dir]] command does not work when an object's motion is set to follow ego.  
+
If '''DISTANCE''' is one (1), object '''oA''' will never reach ego, unless either object is set to ignore other objects using the '''[[ignore.objs]]''' command.
  
You can use the '''follow.ego''' command on the ego object itself, but it will instantaneously reach its destination on the next cycle, and switch back to normal motion style.  
+
If the '''[[set.dir]]''' command is used when an object is following ego, the object will move in the new direction for one [[interpreter cycle]] before AGI changes the direction back toward ego.  
</blockquote>
 
  
=== Example ===
+
You can use the '''follow.ego''' command on the ego object itself, but it will instantaneously reach its destination on the next cycle, and switch back to 'normal' movement mode.
  
<code>follow.ego(o1, 1, f99); //object will begin moving toward ego</code>
+
== Possible Errors ==
  
=== Required Interpreter Version ===
+
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]].
  
<blockquote>
+
== Example ==
Available in all AGI versions.
 
</blockquote>
 
  
=== Bytecode Value ===
+
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="agi">
 +
follow.ego(o1, 2, f99); [ object will begin moving toward ego
 +
if(isset(f99))
 +
    {
 +
    print("TAG! You're it!")
 +
    reset(f99);
 +
    }
 +
</syntaxhighlight>
  
<blockquote>
+
== Technical Information ==
0x53
 
</blockquote>
 
  
=== See Also ===
+
{| 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:'''
 +
| 83 (0x53 hex)
 +
|}
  
*
+
== See Also ==
  
&nbsp;
+
'''[[set.dir]]'''<br />
 
+
[[Category:Commands]]<br />
[[Category:References]]
 
[[Category:Object Commands]]
 
[[Category:View Commands]]
 
[[Category:Logic]]
 

Latest revision as of 18:46, 30 March 2019

The follow.ego command sets a screen object's movement mode to ‘follow ego’, meaning it will always move toward the ego object (o0).

Syntax

follow.ego(obj oA, byt DISTANCE, flg fCAUGHT);

Remarks

Object oA begins moving toward ego. AGI calculates the direction to move based on distance from ego. If an obstacle is encountered, AGI will move in a random direction for a few interpreter cycles before trying again to follow ego. The number of cycles that it will move before trying again is the greater of the distance to ego or the object's current step size.

Setting the movement mode to ‘follow ego’ will automatically enable the object for updating if not currently enabled. The cycling property is not modified by the follow.ego command.

Flag fCAUGHT is reset to FALSE when the command is executed.

If DISTANCE is zero (0), AGI uses object oA’s current step size as the DISTANCE value. When oA is within DISTANCE pixels of ego's position, the object will stop moving, flag fCAUGHT is set, and the object switches to ‘normal’ movement mode.

If DISTANCE is one (1), object oA will never reach ego, unless either object is set to ignore other objects using the ignore.objs command.

If the set.dir command is used when an object is following ego, the object will move in the new direction for one interpreter cycle before AGI changes the direction back toward ego.

You can use the follow.ego command on the ego object itself, but it will instantaneously reach its destination on the next cycle, and switch back to 'normal' movement mode.

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.

Example

Code:
follow.ego(o1, 2, f99); [ object will begin moving toward ego
if(isset(f99)) 
    {
    print("TAG! You're it!")
    reset(f99);
    }

Technical Information

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

See Also

set.dir