variable_instance_set not working?
I'm trying to use variable_instance_set to declare and initialize a new variable, but when I check afterwards to see if the created variable exists, it does not.
Here's my code:
variable_instance_set(instance_id, "copper", 5);
if (variable_instance_exists(instance_id, "copper")) {
var msg = "Exists!";
} else {
var msg = "Does not Exist!";
}
show_message(msg);
Posted Sep 13, 2020, 8:09 AM UTC
18
instance_id is a build-in variable. It's an array and read-only and therefore does not contain a valid ID. Use a different variable name or access an ID in the array like the documentation describes.
The documentation I read says the first slot is for the id of the instance that the variable belongs to.
The "first slot"? The first parameter of the function you mean? Yeah - that's a bit stupid from the documentation to call it that.
Anyway, if
instance_idis highlighted in your code like build in variables likexandy, I'd change it.How to you set
instance_id?If the first parameter isn't the instance id for the instance the variable belongs to, then what is it supposed to be?
The first parameter is the instance, no doubt. You just can't call it the exact name
instance_idused in the documentation because that is also the name of a build-in readonly variable.That's why I asked how you set
instance_idin your example...