Difference between revisions of "DelayEvent"

From Dragon Age Toolset Wiki
Jump to: navigation, search
(a fancied up and trimmed down version of the heartbeat example. Works for everyone?)
(Examples)
 
(4 intermediate revisions by 2 users not shown)
Line 30: Line 30:
 
== Remarks ==
 
== Remarks ==
 
<!-- This section contains additional comments, observations and known issues. -->
 
<!-- This section contains additional comments, observations and known issues. -->
With a negative or zero time in fSeconds, the event will run on the next AI update.
+
With a negative or zero time in fSeconds, the event will run on the next AI update.
 +
 
 +
The <code>scriptname</code> parameter does not work for an [[area]].
  
 
== Examples ==
 
== Examples ==
 
<!-- This section contains examples transcluded from the snippet library. -->
 
<!-- This section contains examples transcluded from the snippet library. -->
 +
If the intention is simply to delay the execution of a script, the function can be called with a dummy event parameter. For example, the snippet
 +
<dascript>
 +
DelayEvent(1.0, OBJECT_SELF, Event(EVENT_TYPE_INVALID), "my_script");
 +
</dascript>
  
This function can be used to create a "heartbeat" event that is sent to a script at regular intervals. For example, if you created the following script named "event_heartbeat":
+
will run the script my_script.ncs on the current object after 1 second.
 +
 
 +
<code>DelayEvent</code> can be used to create a heartbeat event that is sent to an object at regular intervals. For example, if you created the following script named "event_heartbeat" it would fire every six seconds after it has been initiated.
  
 
<dascript>
 
<dascript>
#include "utility_h"
 
#include "wrappers_h"
 
 
#include "events_h"
 
#include "events_h"
  
 
void main()
 
void main()
 
{
 
{
 +
    // extract event type from current event
 
     event ev = GetCurrentEvent();
 
     event ev = GetCurrentEvent();
     int nEventType = GetEventType(ev); //extract event type from current event
+
     int nEventType = GetEventType(ev);
 +
 
 
     switch(nEventType)
 
     switch(nEventType)
 
     {
 
     {
 
         case EVENT_TYPE_HEARTBEAT:
 
         case EVENT_TYPE_HEARTBEAT:
 
         {
 
         {
             //Insert whatever code you need to execute on heartbeats here
+
             // insert whatever code you need to execute on every heartbeat here
             DelayEvent(6.0f, GetHero(), Event(EVENT_TYPE_HEARTBEAT), "event_heartbeat");
+
 
 +
            // schedule a delayed event on this object to call this script again
 +
             DelayEvent(6.0, OBJECT_SELF, Event(EVENT_TYPE_HEARTBEAT), "event_heartbeat");
 +
 
 
             break;
 
             break;
 
         }
 
         }
Line 57: Line 68:
 
}
 
}
 
</dascript>
 
</dascript>
 
+
To associate a heartbeat with a particular object you can use that object's event-handling script and omit the <code>scriptname</code> parameter.
This event would fire every six seconds. To associate a heartbeat with a particular creature you can use that creature's event-handling script and omit the scriptname parameter.
+
  
 
<!-- == See also == -->
 
<!-- == See also == -->

Latest revision as of 16:53, 29 September 2010

Signals a delayed event to the specified object.

void DelayEvent(
float fSeconds,
object oObject,
event evEvent,
string scriptname = ""
);
Parameters:
fSeconds
The number of seconds for which to delay the event
oObject
The object to signal the event to
evEvent
The event to signal
scriptname
If specified overides the default script
Returns:

Nothing.

Source:

script.ldf

Description

Signals a delayed event to the target object.

Remarks

With a negative or zero time in fSeconds, the event will run on the next AI update.

The scriptname parameter does not work for an area.

Examples

If the intention is simply to delay the execution of a script, the function can be called with a dummy event parameter. For example, the snippet

DelayEvent(1.0, OBJECT_SELF, Event(EVENT_TYPE_INVALID), "my_script");

will run the script my_script.ncs on the current object after 1 second.

DelayEvent can be used to create a heartbeat event that is sent to an object at regular intervals. For example, if you created the following script named "event_heartbeat" it would fire every six seconds after it has been initiated.

#include "events_h"
 
void main()
{
    // extract event type from current event
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
 
    switch(nEventType)
    {
         case EVENT_TYPE_HEARTBEAT:
         {
             // insert whatever code you need to execute on every heartbeat here
 
             // schedule a delayed event on this object to call this script again
             DelayEvent(6.0, OBJECT_SELF, Event(EVENT_TYPE_HEARTBEAT), "event_heartbeat");
 
             break;
         }
    }
}

To associate a heartbeat with a particular object you can use that object's event-handling script and omit the scriptname parameter.