Fox, on 06 February 2013 - 06:47 PM, said:
That can be explained by the way they're implemented. When an endevent is encountered but the event was already defined previsouly, a JUMP instruction that points to the beginning of the old one is placed at the end of the new one. So yes, events defined later run earlier. [NOTE: jump shouldn't really be used by user CON code.]
Quote
onevent EVENT_SPAWN ifactor PIGCOP spritepal 21 endevent onevent EVENT_SPAWN ifactor PIGCOP ifspawnedby RECON spritepal 22 endevent
The intended effect would be that Pig Cops would have palette 21, except those spawned by a Recon Patrol Vehicle which would have palette 22. However this is not what actually happens, instead all Pig Cops would have palette 21 because the first onevent is called later.
That code seems pretty artificial to me, and just having that logic in one "ifactor PIGCOP" branch in EVENT_SPAWN is much more readable IMO. The way I see it, event chaining is mainly a mechanism to allow modules to define independent behavior for a particular event. For example because each module needs EVENT_SPAWN for their custom actors.
Quote
onevent EVENT_SPAWN ifactor PIGCOP spritepal 21 endevent onevent EVENT_SPAWN ifactor PIGCOP break endevent
This sample code is meant to make all Pig Cops have palette 21, but nothing will happen because of the break command in the second onevent. And I don't think this should happen, since when used in a state the break command only affects the code of the state.
Now this is interesting, and it can also be explained by what was said above: the two EVENT_SPAWN parts effectively become one block of code. I kind of agree that the expected behavior for break is "jump to end of event" (i.e. what is called "return" in most imperative programming languages). Shall we say that for now, "if a break is used inside an event that is multiply defined, the behavior is undefined"? (That is, one should not rely on it stay the same in the future.)