Difference between revisions of "ActionDoCommand"

From NWN Lexicon
Jump to: navigation, search
m
Line 1: Line 1:
 
+
{{DISPLAYTITLE:ActionDoCommand(action)}}{{bug}}
 
 
 
 
 
 
=ActionDoCommand(action)=
 
 
 
 
Inserts a command into the Action Queue.
 
Inserts a command into the Action Queue.
 
 
<nwscript>
 
<nwscript>
 
void ActionDoCommand(
 
void ActionDoCommand(
Line 13: Line 7:
 
</nwscript>
 
</nwscript>
  
====Parameters====
+
===Parameters===
  
''aCommand''
+
;aCommand
 +
:Void returning function to execute (ignore "action" data type).
  
Void returning function to execute (ignore "action" data type).
+
===Description===
 +
Inserts the function call aCommand into the Action Queue, ensuring the calling object will perform actions in a particular order.
  
<br />
+
Without the use of this function, in general, any function not beginning with "Action" will not be inserted into the queue. This means they will preempt other, previously called functions in the Action Queue and execute immediately.
  
====Description====
+
===Remarks===
 +
The target of this function is the object making the call. If it's neccessary to command other objects or NPCs then use [[AssignCommand]](). ActionDoCommand() can be nested inside of an AssignCommand() call to add a Command to the targeted object's action queue.
  
Inserts the function call aCommand into the Action Queue. Generally, any function not beginning with ‘Action’ will not be inserted into the queue. Functions called without the use of ActionDoCommand will preempt other previously called functions in the Action Queue and execute immediately.
+
ActionDoCommand() can only accept void-returning functions (and, of course, Bioware defined action-returning functions; however, that'd be a silly use of this function, as those already add their actions to the queue). If you want to use a function that returns a value, you will have to wrap that function in a void-returning function call. For an example of a void-returning wrapper function, see [[CreateObjectVoid]]().
  
<br /><br />
+
Note that, though it takes an "action" type as a parameter, NWScript doesn't allow you to use the action keyword. (BioWare can put it in function declarations, but we can't use it in function declarations ourselves.) So <span class="code">action aDo = SendMessageToPC(oPC, "Message");</span> will not work. You need to put the actual SendMessage... (or whatever) inside the ActionDoCommand() call like so: <span class="code">ActionDoCommand(SendMessageToPC(oPC, "Message"));</span>.
  
====Remarks====
+
The use of void would work exactly the same as action commands in the sense of ActionDoCommand(), however, but code executes instead of a physical action. However, in some cases, such as doing <span class="code">ActionDoCommand(SpeakString("Hello"));</span> would be the same as <span class="code">ActionSpeakString("Hello");</span>.
  
The target of this function is the object making the call. If it's neccessary to command other objects or NPCs then use AssignCommand(). ActionDoCommand() can be nested inside of an AssignCommand() call to add a Command to the targeted objects queue as an Action. <br /><br /> Also note that ActionDoCommand can only accept void returning functions (and, of course, Bioware defined "action" returning functions, however, that'd be a silly use of this function) - if you want to use a function that returns a value, you will have to wrap that function in a void returning function call. <br /><br /> Note that, though it takes an "action" type as a parameter, nwscript doesn't allow you to do stuff like: <br /> action aDo=SendMessageToPC(oPC, "Message"); <br /> You need to put the actual SendMessage... (or whatever) inside the ActionDoCommand 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. <br /><br /> The use of void would work exactly the same as action commands in the sense of ActionDoCommand, however, but code executes instead of a phisical action. However, in some cases, such as doing ActionDoCommand(SpeakString("Hello")) would be the same as ActionSpeakString("Hello"); <br /><br /> It should also be noted that ActionDoCommand() will not function on an object which does not have an Action Queue.
+
ActionDoCommand() will not function on an object which does not have an Action Queue.
 
 
<br />
 
 
 
====Known Bugs====
 
  
 +
===Known Bugs===
 +
{{stub section}}
 
When used in a script during the OnSpawn event, its possible for a creature to assume strange behavior.
 
When used in a script during the OnSpawn event, its possible for a creature to assume strange behavior.
  
<br />
+
===Version===
 
 
====Version====
 
  
 
1.61
 
1.61
  
====Example====
+
===Example===
  
 
<nwscript>
 
<nwscript>
// script without ActionDoCommand()
+
// Without ActionDoCommand()
// in this example the NPC will first speak
+
// In this example the calling NPC will first speak the string
// the string "here's my seat", and then
+
// "here's my seat", and then walk to the chair and sit.
// walk to the chair, and sit.
 
 
{
 
{
    object oNPC = GetObjectByTag("some_npc");
+
    object oChair = GetObjectByTag("chair");
    object oChair = GetObjectByTag("chair");
+
    ActionMoveToObject(oChair);
 
+
    SpeakString("Here's my seat!");
    ActionMoveToObject(oChair);
+
    ActionSit(oChair);
    SpeakString("Here's my seat!");
 
    ActionSit(oChair);
 
 
}
 
}
  
// script with ActionDoCommand()
+
// With ActionDoCommand()
// in this example the NPC will execute the  
+
// In this example the NPC will execute the functions in the order
// functions in the order given (as they are in
+
// given (as they are in the NPCs Action Queue): first walk to the
// the NPCs Action Queue): first walk to the chair,
+
// chair, then speak the string and sit down.
// then speak the string, and sit down.
 
 
{
 
{
    object oNPC = GetObjectByTag("some_npc");
+
    object oChair = GetObjectByTag("chair");
    object oChair = GetObjectByTag("chair");
+
    ActionMoveToObject(oChair);
 
+
    ActionDoCommand(SpeakString("Here's my seat!"));
    ActionMoveToObject(oChair);
+
    ActionSit(oChair);
    ActionDoCommand(SpeakString("Here's my seat!"));
 
    ActionSit(oChair);
 
 
}
 
}
 
</nwscript>
 
</nwscript>
  
====See Also====
+
===See Also===
  
 
{| class="seealso"
 
{| class="seealso"
 
| width="1px" align="right" valign="top" | <font color="gray">functions: </font>
 
| width="1px" align="right" valign="top" | <font color="gray">functions: </font>
|
+
|[[  MoveToNewLocation  | MoveToNewLocation ]]
[[  MoveToNewLocation  | MoveToNewLocation ]]
+
|}<br />
|-
+
----
|}
 
  
<br />
+
<font color="gray">author: Ryan Hunt, editor: Jasperre, additional contributor(s): Jens Eggert, Graziano Lenzi, Lilac Soul, Jasperre</font>
----
 
<font color="gray">  author: Ryan Hunt, editor: Jasperre, additional contributor(s): Jens Eggert, Graziano Lenzi, Lilac Soul, Jasperre</font><br />  <br />
 
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:Action_on_Object_Functions]]
 
[[Category:Action_on_Object_Functions]]

Revision as of 00:06, 11 September 2012

Red bug icon.png Warning: This function has a known bug and may not work as expected in some situations. See Known Bugs for details.

Inserts a command into the Action Queue.

void ActionDoCommand(
    action aCommand
);

Parameters

aCommand
Void returning function to execute (ignore "action" data type).

Description

Inserts the function call aCommand into the Action Queue, ensuring the calling object will perform actions in a particular order.

Without the use of this function, in general, any function not beginning with "Action" will not be inserted into the queue. This means they will preempt other, previously called functions in the Action Queue and execute immediately.

Remarks

The target of this function is the object making the call. If it's neccessary to command other objects or NPCs then use AssignCommand(). ActionDoCommand() can be nested inside of an AssignCommand() call to add a Command to the targeted object's action queue.

ActionDoCommand() can only accept void-returning functions (and, of course, Bioware defined action-returning functions; however, that'd be a silly use of this function, as those already add their actions to the queue). If you want to use a function that returns a value, you will have to wrap that function in a void-returning function call. For an example of a void-returning wrapper function, see CreateObjectVoid().

Note that, though it takes an "action" type as a parameter, NWScript doesn't allow you to use the action keyword. (BioWare can put it in function declarations, but we can't use it in function declarations ourselves.) So action aDo = SendMessageToPC(oPC, "Message"); will not work. You need to put the actual SendMessage... (or whatever) inside the ActionDoCommand() call like so: ActionDoCommand(SendMessageToPC(oPC, "Message"));.

The use of void would work exactly the same as action commands in the sense of ActionDoCommand(), however, but code executes instead of a physical action. However, in some cases, such as doing ActionDoCommand(SpeakString("Hello")); would be the same as ActionSpeakString("Hello");.

ActionDoCommand() will not function on an object which does not have an Action Queue.

Known Bugs

Information icon.png This section of the article is a stub. You can help the NWN Lexicon by expanding it.

When used in a script during the OnSpawn event, its possible for a creature to assume strange behavior.

Version

1.61

Example

// Without ActionDoCommand()
// In this example the calling NPC will first speak the string
// "here's my seat", and then walk to the chair and sit.
{
    object oChair = GetObjectByTag("chair");
    ActionMoveToObject(oChair);
    SpeakString("Here's my seat!");
    ActionSit(oChair);
}
 
// With ActionDoCommand()
// In this example the NPC will execute the functions in the order
// given (as they are in the NPCs Action Queue): first walk to the
// chair, then speak the string and sit down.
{
    object oChair = GetObjectByTag("chair");
    ActionMoveToObject(oChair);
    ActionDoCommand(SpeakString("Here's my seat!"));
    ActionSit(oChair);
}

See Also

functions:  MoveToNewLocation


author: Ryan Hunt, editor: Jasperre, additional contributor(s): Jens Eggert, Graziano Lenzi, Lilac Soul, Jasperre