AssignCommand(object, action)
Assigns an action command to a creature to act on.
void AssignCommand( object oActionSubject, action aActionToAssign );
Parameters
oActionSubject
The target that will perform the action.
aActionToAssign
The action to perform.
Description
Assigns aActionToAssign to oActionSubject's action queue.
No return value, but if an error occurs, the log file will contain "AssignCommand failed." If the object doesn't exist, nothing happens.
Note that aActionToAssign is more or less a callback function; aActionToAssign can be a void like ClearAllActions().
Remarks
A common mistake on AssignCommand seems to be to use OBJECT_SELF. OBJECT_SELF is a constant so it is more of a NULL pointer than a "this" pointer. If you use it in the AssignCommand or similar functions the creature will attempt to perform the action against itself which most often seems to not be what the person using it intended.
Also note that, OBJECT_SELF, if used in the aActionToAssign, will be oActionSubject. For instance:
AssignCommand(oPC, SpeakString(GetName(OBJECT_SELF)));
will cause oPC to speak his own name, not the name of the owner of the script.
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 AssignCommand 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.
Version
1.29
See Also
functions: | ActionDoCommand | ActionWait | ClearAllActions | MoveToNewLocation | SetCommandable |
categories: | Action on Object Functions |
author: Charles Feduke, editor: Lilac Soul, additional contributor(s): Edward Wilson
Send comments on this topic.