DelayCommand(float, action)

From NWN Lexicon

Delays an assigned action for a period of time.

void DelayCommand(
    float fSeconds,
    action aActionToDelay
);

Contents

[edit] Parameters

fSeconds
Number of seconds to delay the command by.
aActionToDelay
Action in the Action Queue to delay.

[edit] Description

Delay aActionToDelay by fSeconds. If an error occurs the log file will contain "DelayCommand failed.".

DelayCommand() is paused/inactive when EffectTimeStop() is in effect.

[edit] Remarks

DelayCommand() is no longer capped by a time limit of 1 game day.

Invalid objects can't execute stuff inside DelayCommand()s, meaning that DelayCommand() should not be used in OnDeath events, or after a call to DestroyObject(OBJECT_SELF);

Note that, though it takes an action type as a parameter, you cannot create your own "action" variables (e.g., you cannot write action aDo = SendMessageToPC(oPC, "Message"); You need to put the actual SendMessage() (or whatever) inside the DelayCommand() call - you can't use the action keyword as a pointer to a function. In fact, the action keyword is unusable, except that BioWare can put it in function declarations, apparently. But we can't use it in function declarations ourselves.

Also, please note that the delay starts when the function containing the call to DelayCommand() finishes. So even no delay at all: DelayCommand(0.0f, ActionToDo()); will postpone the execution of ActionToDo() until after everything else in the same function has finished.

As of HotU, DelayCommand()'s order, if used with the same delay, has been swapped for performance reasons. A script with:

DelayCommand(10.0, Foobar());
DelayCommand(10.0, Nothing());

...will now call Nothing() before Foobar(). This is unlikely to affect anything and it is much better to put both Foobar() and Nothing() in a wrapper as noted in Known Bugs and the Code below.

All functions passed within the DelayCommand function are not executed until the delay has passed. This means that DelayCommand(6.0, Foobar(GetLocation(OBJECT_SELF))) will pass the location of OBJECT_SELF after those 6 seconds, and not the location at the time the DelayCommand function is first called.

[edit] Known Bugs

DelayCommand() can now be used in area transitions without losing the command.

Also note that using DelayCommand() on consecutive lines with the same amount of delay may produce unexpected results as of the HotU release. Your code is less likely to break and will be more efficient if you place the sequence of actions in a separate function and then delay the call to that function. See code example below.

DelayCommand() does not work on Encounters. [1]

[edit] Version

1.62

[edit] Example

// The old way of doing it
void main()
{
    //Make the NPC "NW_BOY" do something with the item "NW_PICKUP"
    object oNPC = GetObjectByTag("NW_BOY");
    object oPickObj = GetObjectByTag("NW_PICKUP");
 
    // Tell anyone nearby that they are leaving
    DelayCommand(3.0f, AssignCommand(oNPC, SpeakString("I'm going.", TALKVOLUME_TALK)));
    // Walk over to oPickObj and pick it up
    DelayCommand(3.0f, AssignCommand(oNPC, ActionPickUpItem(oPickObj)));
    // Destroy NPC
    DelayCommand(3.0f, AssignCommand(oNPC, ActionDoCommand(DestroyObject(oNPC))));
}
 
 
// The new way of doing it
void DoIt(object oNPC, object oPickObj)
{
    // Tell anyone nearby that they are leaving
    AssignCommand(oNPC, SpeakString("I'm going.", TALKVOLUME_TALK));
    // Walk over to oPickObj and pick it up
    AssignCommand(oNPC, ActionPickUpItem(oPickObj));
    // Destroy NPC
    AssignCommand(oNPC, ActionDoCommand(DestroyObject(oNPC)));
}
 
void main()
{
    //Make the NPC "NW_BOY" do something with the item "NW_PICKUP"
    DelayCommand(3.0f, DoIt(GetObjectByTag("NW_BOY"), GetObjectByTag("NW_PICKUP")));
}

[edit] See Also

functions:  EffectTimeStop

[edit] References

  1. "DelayCommand and Encounters" Thread on the BioBoards



 author: Charles Feduke, editor: Jasperre, additional contributor(s): Dieter, Bob Stewart, Lilac Soul, Grimlar, Jasperre

Personal tools
Categories