netoxinaa
Member
Hello. I'm having a little issue trying to compare an item object with its constructor.
I have this constructor function called Cellphone and my player has in its inventory an object made from that constructor. So what I want is to check if the player has in its inventory the item Cellphone.
So I have this:
where itemHeld it's the item in my inventory and _item it's an argument (in this case, it is the constructor's name: Cellphone).
instanceof (itemHeld) returns the string "Cellphone", which is ok, but _item returns an instance id (10027), so the check returns false. Changing _item to instanceof( _item ) just returns undefined.
I could easily just type if ... == "Cellphone" for this one but I want it to work with any other item possible.
Is there a way I can get the name of a constructor to achieve this? Something like how object_index works with normal instances?
I have this constructor function called Cellphone and my player has in its inventory an object made from that constructor. So what I want is to check if the player has in its inventory the item Cellphone.
So I have this:
GML:
if (instanceof(itemHeld) == _item) return true;
instanceof (itemHeld) returns the string "Cellphone", which is ok, but _item returns an instance id (10027), so the check returns false. Changing _item to instanceof( _item ) just returns undefined.
I could easily just type if ... == "Cellphone" for this one but I want it to work with any other item possible.
Is there a way I can get the name of a constructor to achieve this? Something like how object_index works with normal instances?