AssignCommand() NWScript command causes the indicated object to execute the indicated command (or function). This execution occurs immediately after the current script finishes, but after any prior assigned commands.
The most common reason for assigning a command is because some commands (notably, the "Action" commands) always affect their calling object. Assigning a command can also be useful for scripts that inflict damage, as the creator of the damaging effect is given credit for that damage (including credit for any kills resulting from that damage).
A less common reason for assigning a command is to make use of the fact that the command is delayed until the current script finishes. This can be more efficient that using
DelayCommand() with a delay of 0.0, and can be useful for delaying a command until certain cleanup operations are finished — such as actually destroying objects or actually removing item properties, neither of which are done while a script executes (they are merely flagged to be done when the script finishes). This is the only circumstance in which assigning a command to OBJECT_SELF has any useful result.
- The object that will execute the command.
- The instruction that will be executed by
oActionSubject. This must be a command or function that returns
oActionSubject does not exist, this command has no result.
The expression passed as the second parameter will be evaluated by the object to which it is assigned, not by the object doing the assigning. Among other implications, this means that any occurrence of OBJECT_SELF will evaluate to the assigned object and any occurrence of
EffectDamage() will be credited to the assigned object. In order to have such an expression refer to / be credited to the assigning object, it must be replaced by a variable set to the value of the expression. That is,
object oMe = OBJECT_SELF; AssignCommand(oSomething, SomeFunction(oMe));