#"other" keyword scope issue in structs?

36 messages · Page 1 of 1 (latest)

old spear
#

when is open() called?

#

Would be good to show the code on that… But I have another question anyway

#

Is this project recently made from 2024.11 and beyond?

#

Depending on how that code for open() is called, I suspect you were relying on what is now deprecated behaviour

#

Game options -> Main -> Deprecated Behaviours

#

There should be an option for other scope w/ methods

#

You can check the box if you just want it to work again

#

It’s more relevant than one would think 😉

#

Yeah okay

#

I definitely am believing it’s due to the other changes

#

GameMaker now has it so other changes to the current self, before applying the new self, from the method call (as this didn’t previously do this)

old spear
#

Well yes, the old way is deprecated

#

You can just change it back for this project if you want

#

Just a checkbox away

#
global.a = { };
global.b = { };
global.c = { };

var f = method(c, function () {
  show_message(self == global.c);  // true
  show_message(other == global.b); // false
  show_message(other == global.a); // true
});

with (global.a) {
  with (global.b) {
    f();
  }
}
#

Basically this is the old behaviour

#

If you go through multiple withs() and call a method bound to another unrelated instance/struct, it’ll have global.a as other

#

The change makes it so global.b is other

#

Making it the last self scope, other in this case

#

This also applies to methods that have a bound scope

#

Calling a method that calls another method, even if the scope is the same, will also push up the self to other, before applying self from the current method scope

#

Which is exactly the issue you’re facing with Snowstate

#

Because struct that you pass in to Snowstate, makes new methods out of all of the events, using the owner as the scope

#

The contents of the code there was defined in a script

#

Script scope is global

#

So doing foo = "bar" would be the same as global.foo = "bar" (you can basically pretend “c” is “global.c”)

#

But otherwise yes

#

You are correct

#

Yes

#

I assume via with() and out of SnowState too, but also yes

#

Actually I believe that is technically 3 scope changes realistically

#

Snowstate, then the method that Snowstate bound the scope of the owner of the state machine to (which I assume is __), then the scope of __

#

But I digress

#

In short, other isn’t truly accurate to rely on in most cases.

If you need to reference that specific instance, it’s best to pass it along in some other matter (function arguments, a struct variable, a fake closure, a global variable, etc)