Notify / Endon / Waittill: Difference between revisions
(New page: == Notify / Endon / Waittill == Image:Nutshell.png These 3 functions can be used to do many things, they are often used to "end" a script/function from running, they can be used t...) |
mNo edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Note|These 3 functions allow you to make a script wait for specific events and then trigger those events in different parts of the scripts.}} | |||
== Notify / Endon / Waittill == | |||
This one ends the function it is inside when 'thread_restart' is triggered on 'level': | |||
level endon ("thread_restart"); | level endon ("thread_restart"); | ||
and | and this triggers the 'killed_player' notification on 'self' (which is a player in this case): | ||
self notify("killed_player"); | self notify("killed_player"); | ||
If you use | If you use 'player waittill("x")' or 'player endon("x")', then using a 'level notify("x")' will not trigger either of them - level is not the same entity as player, and all entities' triggers are independant. | ||
Using the functions is easy. Firstly, decide which entity you want to wait for the trigger on. This is a player most of the time, but if you want a global trigger then use 'level'. | |||
Then you must decide which trigger to use. You can choose either "endon" or "waittill" - they are both self explanatory, one will end the function it is running in when triggered, and the other will 'wait' until the specified trigger. | |||
Then you must decide which | |||
---- | ---- | ||
Next you decide on a unique | Next you decide on a unique name for the trigger. For example... | ||
level endon("a_unique_call"); | level endon("a_unique_call"); | ||
And to activate this trigger, you use notify on the same entity (level): | |||
level notify("a_unique_call"); | level notify("a_unique_call"); | ||
You can use as many waittill and endon functions as you want on an entity, in different functions. They will all be triggered by a notify. | |||
Here is a quick example of it in use in multiple threads in the DM gametype... | Here is a quick example of it in use in multiple threads in the DM gametype... | ||
<pre> | |||
spawnPlayer() | spawnPlayer() | ||
{ | { | ||
self notify("spawned"); | self notify("spawned"); | ||
/*... Code | /*... Code snipped ... this is another type of | ||
comment that can span multiple lines. */ | |||
} | } | ||
Callback_PlayerKilled( | Callback_PlayerKilled(attacker, some other arguments) | ||
{ | { | ||
self endon("spawned"); | self endon("spawned"); //this makes callback_playerkilled() terminate when "spawned" is triggered in spawnplayer(). | ||
} | } | ||
</pre> | |||
[[Category:Call of Duty]] | |||
[[Category:Scripting]] | |||
Latest revision as of 21:36, 28 July 2009
Notify / Endon / Waittill
This one ends the function it is inside when 'thread_restart' is triggered on 'level':
level endon ("thread_restart");
and this triggers the 'killed_player' notification on 'self' (which is a player in this case):
self notify("killed_player");
If you use 'player waittill("x")' or 'player endon("x")', then using a 'level notify("x")' will not trigger either of them - level is not the same entity as player, and all entities' triggers are independant.
Using the functions is easy. Firstly, decide which entity you want to wait for the trigger on. This is a player most of the time, but if you want a global trigger then use 'level'.
Then you must decide which trigger to use. You can choose either "endon" or "waittill" - they are both self explanatory, one will end the function it is running in when triggered, and the other will 'wait' until the specified trigger.
Next you decide on a unique name for the trigger. For example...
level endon("a_unique_call");
And to activate this trigger, you use notify on the same entity (level):
level notify("a_unique_call");
You can use as many waittill and endon functions as you want on an entity, in different functions. They will all be triggered by a notify.
Here is a quick example of it in use in multiple threads in the DM gametype...
spawnPlayer() { self notify("spawned"); /*... Code snipped ... this is another type of comment that can span multiple lines. */ } Callback_PlayerKilled(attacker, some other arguments) { self endon("spawned"); //this makes callback_playerkilled() terminate when "spawned" is triggered in spawnplayer(). }