- Code: Select all
Global.ActorLeaving( Other);
// Calls non-state ActorLeaving event from this class
- Code: Select all
//=============================================================================
// > QUESTION: How exactly do States work?
//=============================================================================
It's a special code flow executed during the actor's native Tick (don't remember if before or after the script Tick event).
Single flow, can define variations of global functions to customize the actor's behaviour during said state.
Flow can be controlled using 'latent' functions:
- Sleep( float Time);
- Stop;
- WaitForLanding(); (pawn only)
- MoveToward, MoveTo, StrafeFacing, etc (pawn only)
- FinishAnim(); (actor playing non-looped animation only)
- Goto operator, paired with a label name (ex: Goto Begin;), this is 100% safer than GotoState from within state.
You can customize flow control using While() loops paired with Sleep(0.0); calls.
- Code: Select all
WaitForEnemy:
while ( Enemy == none )
Sleep(0.0);
Attack:
Attack();
if ( Enemy == none || Enemy.bDeleteMe || Enemy.Health <= 0 )
{
Enemy = none;
Goto WaitForEnemy;
}
Goto Attack;
- Code: Select all
event EndState()
//
{
Guy = none;
// If guy = none, the state ends
}
EndState() is a state-only script function, it's immediately called after your GotoState() call changes the actor into a different (or none) state, executed before the next line of code, consider the current state's EndState() as an extension of your GotoState() call.
Something similar occurs with the new state's BeginState() event.
In this case, we're setting Guy=none because he's either left the zone or the lottery has finished, it's a cleanup routine and a very responsible way of coding.
- Code: Select all
selection = FRand(); //Generate float ranged [0,1)
if (Selection >= 0.8)
else if (Selection >= 0.7)
else
If we check >= 0.8 before >= 0.7, then the >= 0.8 will never evaluate, it's simple logical reasoning.
There's like ten different ways of doing a random chance check with more than two results, each one requires a different reasoning.
Just take a look:
- Code: Select all
if ( Selection < 0.7)
fail
else if ( Selection < 0.8 )
one weapon
else
two weapons
- Code: Select all
if ( FRand() < 0.7 )
fail
else if ( FRand() < 0.33 )
one weapon
else
two weapons
They all do the same.