Talk:SetLocalString

From NWN Lexicon

Contents

[edit] Known Bugs : Deprecated

The following report has been removed, since it no longer appears to be true. See discussion at http://forum.bioware.com/topic/505734-setting-local-variables-on-newly-created-objects/ Proleric (talk) 17:00, 23 May 2014 (UTC)

[edit] Known Bugs

Setting strings on objects just created can fail to work. Use ActionDoCommand(void) to set a string on a newly created object. This bug appears in all of the SetLocal* functions (each has been annotated to reference this function for the work around to this problem).


[edit] Version

1.61

[edit] Example

// sets a string to OBJECT_SELF which can be later retrieved
// using something similar to:
// string sValue = GetLocalString(OBJECT_SELF, "foo");
void main()
{
     object oThis = OBJECT_SELF;
     string sKey = "foo";
     string sValue = "some string";
     SetLocalString(oThis, sKey, sValue);
}
 
/* the following two examples assume arbitrary values
    previously specified for nObjectType, sTemplate, and 
    lLocation.  See CreateObject(int, string, location, int) for more 
    information.
*/
 
// INCORRECT
// the following will not work on a freshly created object
object oTarget = CreateObject(nObjectType, sTemplate, lLocation, FALSE);
SetLocalString(oTarget, "STRING_NAME", "This is my string value");
 
// CORRECT
// the following WILL work on a freshly created object
object oTarget = CreateObject(nObjectType, sTemplate, lLocation, FALSE);
// Remember: You cannot define an action (action aAction =) 
// so we must pass it directly into the AssignCommand.
AssignCommand(oTarget, ActionDoCommand(SetLocalString(oTarget, "STRING_NAME", "This is my string"));
Personal tools
Categories