View Full Version : Little Question about States

2nd Oct 2001, 07:04 PM
Is there any difference between a function declared in a state and the same function outside the state when the function appears only once in the class?

What i want to know is if it is importent where the function is Implemented.

A little xample:

In Projectile.uc you have the state flying and some related function like touch, processtouch, explode and hitwall.

When flying is the only state in the class, normaly only touch has to be in there. No im unsure: does it matter if processtouch is declared outside the state, or is it definivly important to put it in? And what about the other functions? When does it matter that the functions need to be declared inside or outside a state?

2nd Oct 2001, 07:14 PM
If i remember correctly, functions in states only get executed if the relevant actor is in that state -- very powerful. Allows you to stipulate that the same function have different behavior depending on context (state).

Also, functions that are not in states are considered global to the class i believe ... So if a given function is called for a class, the current state if any will execute its version of the function if it exists; if not, the version that resides outside of states is executed. You can also force this to happen as well, but i don't remember for sure how, it might be by using 'Global', as in 'Global.ProcessTouch()' ... HTH

3rd Oct 2001, 12:30 AM
All classes actually have a default state, so technically there are no global functions. Technically, but not practically. Basically you can define a function global by not placing it within a state and it will become the default function called whenever a class isn't in a specific state (after a gotostate('') for instance). When you define a function inside a state then that version will be called instead of the global one if the object is currently in that state. Pretty simple really, and it can be really useful for gameplay code as it allows you to change the behaviour of an object dramatically based on any number of variables with very little overhead. Just think of how inheritance works - in this case your are creating a special case version of a function to override the global one.

Hope that makes sense...I'm a bit tired to be explaining these things really... :)