News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 6th May 2008, 01:09 PM   #1
SuperApe
Registered Monkey
 
SuperApe's Avatar
 
Join Date: Mar. 20th, 2004
Location: Inna Jungle
Posts: 333
State flow

This has been a little unclear to me and after some searching, I've decided to open this thread to ask how the flow is directed upon state change. There is some explanation on the wiki with regards to GotoState():
Quote:
Originally Posted by UnrealWiki
GotoState (optional name NewState, optional name Label)
Switches to a new state. State code execution begins at the specified label or at "Begin:" if Label is not specified. Before the state is changed the old state's EndState function is called. After the state changed BeginState of the new state is called.
But it isn't as clear to me as I'd like.

Say, I've got an actor in state "StartUp".

Given:
Code:
state StartUp
{
  function EndState()
  {
    Log("StartUp's EndState function was reached.");
  }
}

state NewState
{
  function BeginState()
  {
    Log("the BeginState function has been reached.");
  }

begin:
  Log("the begin label has been reached.");

blahblah:
  Log("the blahblah label has been reached.");
}
... I'm now realizing I should just test this code and see for myself ... I suppose I can leave this thread to help answer this question for others.

Anyway, the question was 'In what order are these points reached when I GotoState("NewState");?'.

My guess is that we would see this in the Log:
Quote:
ScriptLog: StartUp's EndState function was reached.
ScriptLog: the begin label has been reached.
ScriptLog: the blahblah label has been reached.
ScriptLog: the BeginState function has been reached.
It's the third one I'm not so sure about. Will the flow trace through all labels shown after "begin:", or just the "begin:" label before going through BeginState()?
__________________
- SuperApe

SuperApe is offline   Reply With Quote
Old 6th May 2008, 02:32 PM   #2
Pfhoenix
Programmer Extraordinaire
 
Pfhoenix's Avatar
 
Join Date: Dec. 17th, 1999
Posts: 60
Incorrect. You should see :

NewState's BeginState called
StartUp's EndState called
then when that object next executes, the label logs will fire as state code starts executing
Pfhoenix is offline   Reply With Quote
Old 8th May 2008, 04:06 AM   #3
Wormbo
 
Wormbo's Avatar
 
Join Date: Jun. 4th, 2001
Location: Germany
Posts: 5,781
State code is executed during actor tick, I think after Timer() and Tick().

Example:
Code:
state A
{
  function fA()
  {
    log("Before GotoState"@GetStateName());
    GotoState('B');
    log("After GotoState"@GetStateName());
  }

  event EndState()
  {
    log("End state A" @ GetStateName());
  }

Begin:
  log("In state A");
  fA();
  log("Still in state A");
}

state B
{
  function fB()
  {
    log("Function B in state" @ GetStateName());
  }

  event BeginState()
  {
    log("BeginState B"@GetStateName());
  }

Begin:
  log("Begin label in state B");
GoingOn:
  log("GoingOn label in state B");
}
Say the above code starts in state A and executes state code. You should get logs like the following:
  1. In state A
  2. Before GotoState A
  3. End state A A
  4. Begin state B B
  5. After GotoState B
  6. Begin label in state B
  7. GoingOn label in state B
Some observations:
  • "Still in state A" will not be logged
  • State code execution continues if the state switch was performed from within state code or a function called from state code
  • Function code execution, even of a state function, continues after state switch, but in the context of the new state. Make sure you don't attempt to call any functions from state A after GotoState('B'), otherwise the game will crash!
  • State code execution of the new state will only start after all functions have returned and only if the state changed happened during state code execution of that object. If the state change happens during another object's state code execution or during an engine event (Timer, Touch, etc.), the new state's code will be executed later, after the object's own Tick() event.
  • Labels are only entry points. State code execution will only stop after GotoState, Stop, latent function calls or the end of the state.
__________________
Wormbo's UT/UT2004/UT3 mods | YouTube channel | PlanetJailbreak/JDN | Unreal Wiki | Liandri Archives
Everything you ever wanted to know about replication| UnrealScript security considerations
<elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
<TNSe> nono
<TNSe> its always funny to find code a week later you dont even remember writing
<Pfhoenix> what's worse is when you have a Star Wars moment
<Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"
Wormbo is offline   Reply With Quote
Old 12th May 2008, 12:04 PM   #4
SuperApe
Registered Monkey
 
SuperApe's Avatar
 
Join Date: Mar. 20th, 2004
Location: Inna Jungle
Posts: 333
Quote:
Originally Posted by Pfhoenix View Post
Incorrect. You should see :

NewState's BeginState called
StartUp's EndState called
then when that object next executes, the label logs will fire as state code starts executing
We should correct the wiki if that is the case. It states that the EndState will be called before the state changes. I think Wormbo is contradicting you in his response. Are you sure about that assertion, Pfhoenix?


Thanks, Wormbo. These are excellent observations and descriptions. (We should integrate some of this back to the wiki when appropriate)

I'll post back if there are any further questions on this.
__________________
- SuperApe

SuperApe is offline   Reply With Quote
Old 13th May 2008, 06:56 AM   #5
Pfhoenix
Programmer Extraordinaire
 
Pfhoenix's Avatar
 
Join Date: Dec. 17th, 1999
Posts: 60
The quickest way to know for sure would be to setup a test script and log() everything.
Pfhoenix is offline   Reply With Quote
Old 13th May 2008, 12:25 PM   #6
SuperApe
Registered Monkey
 
SuperApe's Avatar
 
Join Date: Mar. 20th, 2004
Location: Inna Jungle
Posts: 333
Right. Thanks.
__________________
- SuperApe

SuperApe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:51 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer