Difference between revisions of "ActionDoCommand"

From NWN Lexicon
Jump to: navigation, search
(Created page with " =ActionDoCommand(action)= Inserts a command into the Action Queue. void  ActionDoCommand(      action  aCommand ); ====Param...")
 
Line 7: Line 7:
 
Inserts a command into the Action Queue.
 
Inserts a command into the Action Queue.
  
 +
<nwscript>
 
  [[void | void ]] ActionDoCommand(
 
  [[void | void ]] ActionDoCommand(
 
      [[action | action ]] aCommand
 
      [[action | action ]] aCommand
 
  );
 
  );
 +
</nwscript>
  
 
====Parameters====
 
====Parameters====
Line 43: Line 45:
 
====Example====
 
====Example====
  
<font color="#007f00">// script without ActionDoCommand()
+
<nwscript>
  </font><font color="#007f00">// in this example the NPC will first speak
+
// script without ActionDoCommand()
  </font><font color="#007f00">// the string "here's my seat", and then
+
  // in this example the NPC will first speak
  </font><font color="#007f00">// walk to the chair, and sit.
+
  // the string "here's my seat", and then
  </font>{
+
  // walk to the chair, and sit.
       <font color="#0000ff">object</font> oNPC = GetObjectByTag(<font color="#00007f">"some_npc"</font>);
+
  {
       <font color="#0000ff">object</font> oChair = GetObjectByTag(<font color="#00007f">"chair"</font>);
+
       object oNPC = GetObjectByTag("some_npc");
 +
       object oChair = GetObjectByTag("chair");
 
   
 
   
 
       ActionMoveToObject(oChair);
 
       ActionMoveToObject(oChair);
       SpeakString(<font color="#00007f">"Here's my seat!"</font>);
+
       SpeakString("Here's my seat!");
 
       ActionSit(oChair);
 
       ActionSit(oChair);
 
  }
 
  }
 
   
 
   
  <font color="#007f00">// script with ActionDoCommand()
+
  // script with ActionDoCommand()
  </font><font color="#007f00">// in this example the NPC will execute the  
+
  // in this example the NPC will execute the  
  </font><font color="#007f00">// functions in the order given (as they are in
+
  // functions in the order given (as they are in
  </font><font color="#007f00">// the NPCs Action Queue): first walk to the chair,
+
  // the NPCs Action Queue): first walk to the chair,
  </font><font color="#007f00">// then speak the string, and sit down.
+
  // then speak the string, and sit down.
  </font>{
+
  {
       <font color="#0000ff">object</font> oNPC = GetObjectByTag(<font color="#00007f">"some_npc"</font>);
+
       object oNPC = GetObjectByTag("some_npc");
       <font color="#0000ff">object</font> oChair = GetObjectByTag(<font color="#00007f">"chair"</font>);
+
       object oChair = GetObjectByTag("chair");
 
   
 
   
 
       ActionMoveToObject(oChair);
 
       ActionMoveToObject(oChair);
       ActionDoCommand(SpeakString(<font color="#00007f">"Here's my seat!"</font>));
+
       ActionDoCommand(SpeakString("Here's my seat!"));
 
       ActionSit(oChair);
 
       ActionSit(oChair);
 
  }
 
  }
 +
</nwscript>
  
 
====See Also====
 
====See Also====

Revision as of 20:23, 25 August 2012



ActionDoCommand(action)

Inserts a command into the Action Queue.

 [[void | void ]] ActionDoCommand(
     [[action | action ]] aCommand
 );

Parameters

aCommand

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


Description

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.



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 objects queue as an Action.

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.

Note that, though it takes an "action" type as a parameter, nwscript doesn't allow you to do stuff like:
action aDo=SendMessageToPC(oPC, "Message");
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.

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");

It should also be noted that ActionDoCommand() will not function on an object which does not have an Action Queue.


Known Bugs

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


Version

1.61

Example

 // script without ActionDoCommand()
 // in this example the NPC will first speak
 // the string "here's my seat", and then
 // walk to the chair, and sit.
 {
      object oNPC = GetObjectByTag("some_npc");
      object oChair = GetObjectByTag("chair");
 
      ActionMoveToObject(oChair);
      SpeakString("Here's my seat!");
      ActionSit(oChair);
 }
 
 // script 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 oNPC = GetObjectByTag("some_npc");
      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