PDA

View Full Version : states


Cooban
17th Aug 2005, 03:57 AM
Hello, does anyone know if there is a function which will return character back to their previous state. For example if a character is in scout state and then suddenly changes to attack state I need a function or way of returning to the scout state again therefore having virtual memory (sort of).

Thanks

SuperApe
17th Aug 2005, 12:27 PM
A function to do this? I don't know of one.
There is a Actor -> bBadStateCode which should cause an Event called RecoverFromBadStateCode(). I don't know how reliable that is.
But, it seems you could use the Event EndState() to set a BACKUP_State var so you can switch it back with your own function.

omegabyte
17th Aug 2005, 07:28 PM
You could try creating an enumeration that contains IDs for each state you have, then have a variable lastState. Then you could create your own GotoState function like this:

enum StateList
{
STATE_ATTACK,
STATE_SCOUT,
STATE_WHATEVER
}

var StateList lastState;
var StateList currentState;

function MyGotoState( StateList newState )
{
switch newState
{
case STATE_ATTACK:
lastState = currentState;
currentState = STATE_ATTACK;
gotostate("Attack");

case STATE_SCOUT:
lastState = currentState;
currentState = STATE_SCOUT;
gotostate("Scout");

case STATE_WHATEVER:
lastState = currentState;
currentState = STATE_WHATEVER;
gotostate("Whatever");
}
}


Then, after you've switched to attack mode, when you're ready to switch back to whatever the previous state was, just go MyGotoState( lastState );

I don't think there's any explicit function built into UT that keeps track of the last state entered. You'll probably have to keep track of the state changes yourself.