Author Topic: Script not working with string variable  (Read 419 times)

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Script not working with string variable
« on: January 28, 2016, 04:46:17 pm »


               

I've become quite annoyed at this.


The following works at the end of a script, destroying the object referenced:



if(GetFirstItemInInventory(OBJECT_SELF)==OBJECT_INVALID)
DestroyObject(GetObjectByTag("250B6_WEAPON1"),0.0);


So, as to avoid creating multiple scripts to do the same thing for multiple objects, I moved the TAG referenced above to a string variable on the object that runs the script line noted above.



sString string 250B6_WEAPON1

I modified the script line above to the following:



string sItem = GetLocalString(OBJECT_SELF, "sString");
object oContainer = GetNearestObjectByTag(sItem);
   
if(GetFirstItemInInventory(OBJECT_SELF)==OBJECT_INVALID)
DestroyObject(oContainer,0.0);

The object in question is no longer destroyed.


Making it DestroyObject(GetObjectByTag("250B6_WEAPON1"),0.0); works.


Having it DestroyObject(oContainer,0.0); does not work.


FP!



               
               

               
            

Legacy_Tchos

  • Sr. Member
  • ****
  • Posts: 454
  • Karma: +0/-0
Script not working with string variable
« Reply #1 on: January 28, 2016, 04:48:29 pm »


               

Is the object you're trying to destroy an inventory item?  If it's being carried by the player or in another object's inventory, you can't use GetNearestObjectByTag for it.



               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Script not working with string variable
« Reply #2 on: January 28, 2016, 05:04:25 pm »


               

Ah, very good! Thanks Tchos, this issue is now resolved ':wub:'


FP!