Difference between revisions of "Follow.ego"
(Created page with "== follow.ego == The '''follow.ego''' command sets an object's motion style to move toward the ego object (o0). [edit] Syntax follow.ego(obj oA, Nu...") |
|||
(4 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | + | 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). | |
− | + | == Syntax == | |
− | |||
− | Syntax | ||
− | + | follow.ego([[screen object|obj]] oA, [[number|byt]] DISTANCE, [[flag|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. | |
− | Object oA begins moving toward ego. | ||
− | + | 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. | |
− | When | + | 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 == | |
− | |||
− | |||
− | == | + | <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> | ||
− | + | == 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:''' | ||
+ | | 83 (0x53 hex) | ||
+ | |} | ||
− | + | == See Also == | |
− | + | '''[[set.dir]]'''<br /> | |
+ | [[Category:Commands]]<br /> |
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
<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>
Technical Information
Required Interpreter Version: | Available in all AGI versions. |
Byte-Code Value: | 83 (0x53 hex) |