1/14/2010

State.Test.02


Test04.GotoState() within function

function PostBeginPlay()
{
    `log("PostBeginPlay is called");
}


function Alpha()
{
    `log("Global Alpha.");
`log("GoToState('B');");
    GoToState('B');
    `log("GoToState in fuction, so it is processed before going into the target state");
}


auto state A
{      
    function Alpha()
    {
       `log("Alpha of A.");      
    }

    event BeginState (Name PreviousStateName)
    {
        `log("BeginState Event of A");
        Global.Alpha();
    }     

    event EndState (Name NextStateName)
    {
       `log("EndState Event of A"); 
    }

Begin:
    `log("Begin: of A");
    Alpha();
    `log("Alpha();from Begin Label of A");
}


state B
{
    function Alpha()
    {
        `log("Alpha of B.");       
    }

event BeginState(Name PreviousStateName)
    {
        `log("BeginState Event of B");
        Alpha();
    }

    event EndState (Name NextStateName)
    {
       `log("EndState Event of B"); 
    }

Begin:
    `log("Begin: of B");
    Alpha();
    `log("Alpha();from Begin Label of B");
}
ScriptLog: PostBeginPlay is called
ScriptLog: BeginState Event of A
ScriptLog: Global Alpha. // called from BeginState Event of A
ScriptLog: GoToState('B');
ScriptLog: EndState Event of A
// Begin Label of state A is skipped

ScriptLog: BeginState Event of B
ScriptLog: Alpha of B. // called from BeginState Event of B.
ScriptLog: GoToState in fuction, so it is processed before going into the target state
// After all the BeginState & EndState event calls are finished, it comes back to state code.
Log: Bringing up level for play took: 0.037182
Log: ########### Finished loading level: 0.188188 seconds
Init: Game engine initialized
Log: Initializing Engine Completed
Log: >>>>>>>>>>>>>> Initial startup: 4.94s <<<<<<<<<<<<<<<
ScriptLog: Begin: of B //it is the start of state code of state B.
ScriptLog: Alpha of B.
ScriptLog: Alpha();from Begin Label of B

- GotoState() within function
When you call GotoState from within a function, it does not go to the destination immediately, rather it goes there once execution returns back to the state code. (The fuction process the part behind the GoToState(). Nevertheless, the BeginState(), EndState() and functions called from them take precedence over state code.


Test05.GotoState() within State Code

function PostBeginPlay()
{
    `log("PostBeginPlay is called");
    //SetTimer(1.5, false,'Alpha');
}


function Alpha()
{
    `log("Global Alpha.");  
}


auto state A
{      
    function Alpha()
    {
       `log("Alpha of A.");      
    }

    event BeginState (Name PreviousStateName)
    {
        `log("BeginState Event of A");
        Global.Alpha();
    }     

    event EndState (Name NextStateName)
    {
       `log("EndState Event of A"); 
    }

Begin:
    `log("Begin: of A");
    `log("GoToState('B');");
    GoToState('B');   
    `log("GoToState in state code, so it isn't processed");
    `log("Alpha();from Begin Label of A");
}


state B
{
    function Alpha()
    {
        `log("Alpha of B.");        
    }

    event BeginState(Name PreviousStateName)
    {
        `log("BeginState Event of B");
        Alpha();
    }

    event EndState (Name NextStateName)
    {
       `log("EndState Event of B"); 
    }

Begin:
    `log("Begin: of B");
    Alpha();
    `log("Alpha();from Begin Label of B");
}
ScriptLog: PostBeginPlay is called
ScriptLog: BeginState Event of A
ScriptLog: Global Alpha.
Log: Bringing up level for play took: 0.035030
Log: ########### Finished loading level: 0.197054 seconds
Init: Game engine initialized
Log: Initializing Engine Completed
Log: >>>>>>>>>>>>>> Initial startup: 5.40s <<<<<<<<<<<<<<<
ScriptLog: Begin: of A
ScriptLog: GoToState('B'); //It gose to the target state immediately. The rest of code in state code is skipped except EndState().
ScriptLog: EndState Event of A
ScriptLog: BeginState Event of B
ScriptLog: Alpha of B.
ScriptLog: Begin: of B
ScriptLog: Alpha of B.
ScriptLog: Alpha();from Begin Label of B

- GotoState() within State Code
When you call GotoState from state code, it goes to the destination immediately.
(The fuction process the part behind the GoToState(). The rest of the state code in the current state is skipped. Nevertheless, the BeginState(), EndState() and functions called from them are processed.

No comments:

Tag