Each actor has 16 variables, numbered 0 to 15, that each hold an integer. Use them to track an actor's state between EVT scripts, share information with other actors, and configure an actor from its formation.
Setting and getting variables
Use SetActorVar and GetActorVar:
Call(SetActorVar, ACTOR_SELF, 0, 1)
Call(GetActorVar, ACTOR_SELF, 0, LVar0) // LVar0 = 1Naming variables
Define an enum to give your variables readable names:
enum ActorVars {
AVAR_Toppled = 0,
AVAR_ToppleTurns = 1,
};
// in EVS_Init:
Call(SetActorVar, ACTOR_SELF, AVAR_Toppled, false)
// in EVS_TakeTurn:
Call(GetActorVar, ACTOR_SELF, AVAR_Toppled, LVar0)
IfTrue(LVar0)
// try to get back up instead of attacking
EndIfCommunicate between actors
An actor can store another actor's ID in a variable to keep track of it. Magikoopa stores the ID of the clone it makes, and later checks whether the clone is still in the battle:
// in the attack that makes a clone
Call(SummonEnemy, CloneFormation, false)
Call(SetActorVar, ACTOR_SELF, AVAR_CloneActorID, LVar0)
// in EVS_Idle
Call(GetActorVar, ACTOR_SELF, AVAR_CloneActorID, LVar0)
Call(ActorExists, LVar0, LVar1)
IfEq(LVar1, true)
// the clone is still in the battle
EndIfFor the full pattern, see battle/actor/magikoopa.c.
To read or set another actor's variable, pass its actor ID in place of ACTOR_SELF. Dry Bones does this to check whether the other Dry Bones in the battle have collapsed:
Call(GetActorVar, LVar0, AVAR_Collapsed, LVar3)Configuring an actor from its formation
The formation sets variables 0 to 3 when the actor spawns, from its .var0, .var1, .var2, and .var3 fields. Fields you leave out are 0. This lets one actor behave differently depending on the battle it's in.
To set a variable from a formation, add the field after the priority:
static Formation frost_goombas = {
OVL_ACTOR_BY_IDX("frost_goomba", BTL_POS_GROUND_B, 10),
OVL_ACTOR_BY_IDX("frost_goomba", BTL_POS_GROUND_C, 9, .var0 = true),
};Bullet Bill uses this. In a normal battle, its formation leaves .var0 as 0. Before Bill Blaster fires one, the blaster sets .var0 of its Bullet Bill formation to true and .var1 to its own actor ID. Bullet Bill reads the variables in its EVS_Init to choose where it starts:
enum ActorVars {
AVAR_FiredFromBlaster = 0,
AVAR_BlasterID = 1,
};
EvtScript EVS_Init = {
Call(BindTakeTurn, ACTOR_SELF, EVS_TakeTurn)
Call(BindIdle, ACTOR_SELF, EVS_Idle)
Call(BindHandleEvent, ACTOR_SELF, EVS_HandleEvent)
Call(GetActorVar, ACTOR_SELF, AVAR_FiredFromBlaster, LVar0)
IfFalse(LVar0)
// float a little above its home position
Else
// start at the mouth of the blaster
Call(GetActorVar, ACTOR_SELF, AVAR_BlasterID, LVar0)
Call(GetActorPos, LVar0, LVar1, LVar2, LVar3)
// ...
EndIf
Return
End
};For the full pattern, see battle/actor/bullet_bill.c and battle/actor/bill_blaster.c.
For bigger differences, such as a different type, HP, or status table, give the actor a variant instead. Each variant is a blueprint defined with OVL_DEF_ACTOR(name), and a formation selects one by writing the actor's name and the variant's name, such as "anti_guy:trio".