Notify / Endon / Waittill: Difference between revisions

From COD Modding & Mapping Wiki
Jump to navigation Jump to search
(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...)
 
No edit summary
Line 1: Line 1:
== [[Notify / Endon / Waittill]] ==
== [[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 to stop a script running until another part of the code is ready for it to continue and it can be used in simple debugging (although, not the only way).
[[Image:Nutshell.png]] These 3 functions allow you to make a script wait for specific events and then trigger those events in different parts of the scripts.


The functions are often used mainly on a player or the level. I will provide an example of each.
This one ends the function it is inside when 'thread_restart' is triggered on 'level':


  level endon ("thread_restart");
  level endon ("thread_restart");


and from any gametype script.
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 "player waittill" or "player endon", then using a "level notify" will not trigger any of the 2.
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.


To use the functions is very easy. First you decide on what you want the function to be called on.  
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'.


If the action is going to happen to a specific player, then use "player" (although, this will need to change depending on how the player is being called, i.e. self, other, user, etc), or if you want the function to work for the entire script, 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 function to use. You need to choose, either "endon" or "waittill", they are both self explanatory, one will end when called, and the other will 'wait'.


----
----


Next you decide on a unique 'call' for the function. For exmaple...
Next you decide on a unique name for the trigger. For example...


  level endon("a_unique_call");
  level endon("a_unique_call");


Now. when you want the 'endon' function to happen, you will use the 'Notify' function...
And to activate this trigger, you use notify on the same entity (level):


  level notify("a_unique_call");
  level notify("a_unique_call");


Anything with the unique call will be activated, so, multiple 'endon' and 'waittill' functions can be placed around your script.
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 endon("disconnect");
   self notify("spawned");
   self notify("spawned");
  self notify("end_respawn");
    
    
   /*... Code Snipped ...*/
   /*... Code snipped ... this is another type of
  comment that can span multiple lines. */
    
    
  self notify("spawned_player");
}
Callback_PlayerKilled(?, ?, ?, ?, ?, ?, ?, ?, ?)
{
  self endon("spawned");
  self notify("killed_player");
 
  attacker notify("update_playerhud_score");
}
spawnSpectator(origin, angles)
{
  self notify("spawned");
  self notify("end_respawn");
}
All the threads depend on those notifies being called.
Here is a quick easy demonstration...
waiting_thread()
{
  level waittill("stop_waitting", user);
  iprintln("This thread has stopped waitting, because " + user.name + " touched the trigger");
  }
  }


  trigger()
  Callback_PlayerKilled(attacker, some other arguments)
  {
  {
   trigger waittill("trigger", user);
   self endon("spawned"); //this makes callback_playerkilled() terminate when "spawned" is triggered in spawnplayer().
  level notify("stop_waitting", user);
  }
  }
</pre>

Revision as of 02:40, 24 October 2008

Notify / Endon / Waittill

These 3 functions allow you to make a script wait for specific events and then trigger those events in different parts of the scripts.

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().
 }