PDA

View Full Version : begin tag and GotoState()


navboy
14th Feb 2002, 02:50 AM
i'm having a problem with begin tag code in the Activated state of a subclassed UTPickup sporadically not executing the first time through it in the game. It's called by a GotoSTate('Activated') in it's non-state function Activate(), and the entry is the same every time, it's just that the item gets destroyed at some point, then another copy spawned and given to a player, then the whole sequence starts again, only after the first time, the begin tag code always executes.

I read that gotostate doesn't happen until execution returns to state code. Well this gotostate is only ever called outside of state code -- there is no state code to return to. So by that logic, control would never transfer to the state, because there's no state code to return to in the block where the gotostate happened. And yet the BeginState() function happens every single time, so it's obviously going to the state every time, just not executing the begin tag the first time through, though it does a majority of the time. It's a makin' my head hurt ... Any ideas?

Blödsinn machen
14th Feb 2002, 08:44 AM
I read that gotostate doesn't happen until execution returns to state code. Well this gotostate is only ever called outside of state code -- there is no state code to return to. So by that logic, control would never transfer to the state, because there's no state code to return to in the block where the gotostate happened. And yet the BeginState() function happens every single time, so it's obviously going to the state every time, just not executing the begin tag the first time through, though it does a majority of the time. It's a makin' my head hurt ... Any ideas?

navboy, to clear things up:

The "GotoState" function causes the actor to go to a new state, and optionally continue at a specified label (if you don’t specify a label, the default is the "Begin" label). You can call GotoState from within state code, and it goes to the destination immediately. You can also call GotoState from within any function in the actor, but that does not take effect immediately: it doesn’t take effect until execution returns back to the state code.
(extract from the UnrealScript Language Reference).

as for your problem, it boggles me. Have you tried explicitly calling GotoState('Activated', 'Begin')?

navboy
14th Feb 2002, 10:32 AM
You can also call GotoState from within any function in the actor, but that does not take effect immediately: it doesn’t take effect until execution returns back to the state code.

It's that last phrase i don't understand. What happens if GotoState was called from outside any state? There's no state code to return "back to" ...


At any rate, yes i'm using explicit 'Begin' ... What seems to be happening is one actor calls MyPickup.Activate() which in turn has the GotoState call (outside of any state). It gets about as far as the BeginState() function then something another actor makes the same call to the same pickup (all in the same tick), only by now it's apparently in state Activated, because that version of Activate runs, which takes me directly to the function i want to run. But the original thread must have just stopped, because the Begin tag is never reached through all of that.

Later in the game after the pickup's been destroyed, then there is only one call to the newly spawned pickup, and everything goes normally, including the begin code which calls the desired function.

Mychaeel
14th Feb 2002, 10:59 AM
What happens if GotoState was called from outside any state? There's no state code to return "back to" ..."Returns back to the state code" is maybe phrased in a confusing way. What's meant is that GotoState is executed after all functions have returned to their respective callers, when execution takes place again at state (code) level.