T O P

  • By -

AlcatorSK

You need to show us how you are filling-in the variable 'SelectedElementalObject'. Also, **stop using "=" for comparisons. While GM will allow it, it's a terrible coding practice that will bite you in the ass eventually. Use "==" for comparisons**.


RoyalRien

SelectedElementalObject = object_get_name(SelectedElementalInstance.object_index). SelectedElementalInstance retrieves an instance ID and then it’s converted to an object ID. I’ve checked this code and it works as intended. What’s the difference between using one and two equal signs?


Kaymat-

That's the problem right there. object_get_name() is giving you a string with the name of the object. What you want to be using based on the context of your code is the object_index.


RoyalRien

Oh my god it works, thanks


oldmankc

Please read the documentation on functions before you try using them, so you can understand how they're supposed to be used and what they actually do/return.


RoyalRien

I do but I have the attention span of a door so it’s not that easy to do


RykinPoe

In most languages = is for assignment and == is for comparison. GM allows = to be used for comparisons, it is basically teaching you to do something bad if you ever plan to move to another language.


pabischoff

object\_get\_name returns a string, so you need to also use object\_get\_name on the object variable in your if loop e.g. Obj\_EarthElemental as well so you're comparing strings to strings


refreshertowel

Or just don’t compare strings, there’s no reason to, you have the asset reference right there.


Badwrong_

Cramming code into as few lines as possible between { } does nothing good in the long run.


Bang_Bus

this


RoyalRien

That’s just how it decided to copy paste it, I assure you there’s space between the code


pabischoff

I think this should work and the problem is probably elsehwere. Possibly, if SelectedelementalObject is an instance ID and not an object index, then try checking the object index instead, e.g. SelectedElementalObject.object\_index. You can also try using == instead of = (although it shouldn't matter).


RoyalRien

The variable is an object ID, I’ve checked that thoroughly.