RefresherTowel
Member
EDIT: I'm running latest beta 306 (I also tested it with beta 300 and the same problem occurred) but at some point previously, it did function correctly as other people are pointing out below, as I've had this code running fine for a long time while working on Alchementalist.
I'm preeeetty sure this is a bug in GMS, so I guess this is more of a PSA, but if I'm actually making a mistake it'd be sweet if someone could point it out.
First, we create a the function
However, if it's pointed at
Finally, to make absolutely sure there's not some weirdness going on with the fact we are referencing a struct to get to
So at the end of all those tests, the results are:
I'm preeeetty sure this is a bug in GMS, so I guess this is more of a PSA, but if I'm actually making a mistake it'd be sweet if someone could point it out.
is_struct()
seems to return true when encountering a function within a struct. Here's the codeblock:
GML:
function MyFunction() {
some_var = 0;
}
MyStruct = {
Function : method(self,MyFunction)
}
// This works fine, a is equal to false
var a = is_struct(MyFunction);
// This line is the simplest version of the problem, b equals true here
var b = is_struct(MyStruct.Function);
/* These lines below are the smallest "production" version of what I'm doing, pulling all the stuff out of a struct and checking to see
what each thing is, in this case both is_struct() AND is_method() will return true (i.e. c and d both equal true) */
var _names = variable_struct_get_names(MyStruct);
var _i = 0;
var c = 0;
var d = 0;
var _source = MyStruct;
repeat(array_length(_names))
{
var _name = _names[_i];
var _value = variable_struct_get(_source, _name);
if (is_struct(_value)) {
c = true;
}
if (is_method(_value)) {
d = true;
}
}
show_debug_message("A is "+string(a)+", B is "+string(b)+", C is "+string(c)+", D is "+string(d));
MyFunction()
. Then we create a struct MyStruct
, and store a method variable called Function
inside it pointing to MyFunction()
. Finally, we run the tests.is_struct()
works fine when pointed directly at MyFunction
.However, if it's pointed at
MyStruct.Function
(which is a method variable and shouldn't register as a struct), it returns true.Finally, to make absolutely sure there's not some weirdness going on with the fact we are referencing a struct to get to
Function
, we get all the variable names from inside the struct and pull them out one by one (or simply one in this case), then get the contents of those variables using variable_struct_get()
, storing them in _value
and then running the conditionals on that variable. In this case, both c
AND d
end up being true.So at the end of all those tests, the results are:
So theA is 0, B is 1, C is 1, D is 1
Function
inside MyStruct
is registering as both a struct and method variable. I doubt that's intended behaviour and it basically breaks is_struct()
when used to see if something is a struct or a method in all but the most naive cases.
Last edited: