Follow.ego

From AGI Wiki
Jump to navigationJump to search

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:

<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)

See Also

set.dir