Aller au contenu

Photo

Script not working with string variable


  • Veuillez vous connecter pour répondre
2 réponses à ce sujet

#1
Fester Pot

Fester Pot
  • Members
  • 1 393 messages

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!



#2
Tchos

Tchos
  • Members
  • 5 050 messages

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.



#3
Fester Pot

Fester Pot
  • Members
  • 1 393 messages

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

FP!