Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-Game: Add support for "other" to be the originating "self" when used inside methods #7349

Closed
1 of 2 tasks
katsaii opened this issue Aug 20, 2024 · 10 comments
Closed
1 of 2 tasks
Assignees
Labels
documentation Improvements or additions to documentation are required by this issue feature request New feature (or a request for one)
Milestone

Comments

@katsaii
Copy link

katsaii commented Aug 20, 2024

Description

For the following GML code:

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

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

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

The self inside of the f() call is correctly global.c, but other ends up being global.a. After a discussion with Russell, this shouldn't be the case, and instead other should equal global.b in this example.

Expected Change

Change other to be the "self" of the calling scope, when used inside of bound functions

Steps To Reproduce

  1. Start GameMaker
  2. Create a new project
  3. Create a new GML script
  4. Copy-paste the example code into this script
  5. Run the project
  6. See the issue

How reliably can you recreate this issue using your steps above?

Always

Which version of GameMaker are you reporting this issue for?

2024.6.2 (Monthly)

Which platform(s) are you seeing the problem on?

Windows, HTML5

Contact Us Package Attached?

  • I have attached my Contact Us Package

Sample Project Added?

  • I have included a small sample project
@katsaii katsaii added the runner-bug In-game bugs with the "GameMaker Studio 2" runtimes label Aug 20, 2024
@stuckie stuckie moved this from Triage to Todo in Team Workload Aug 20, 2024
@stuckie stuckie added this to the 2024.10 milestone Aug 20, 2024
@gnysek
Copy link
Contributor

gnysek commented Aug 20, 2024

I think that it also doesn't work as it should in case of instances, and local functions, but I was waiting to check it and report correctly until #7125 comes into beta, as that could change a lot.

@rwkay
Copy link

rwkay commented Aug 27, 2024

This is not a bug as the other is not changed at the function call boundary the other is deliberately preserved at the method call for f() - it is the same other as at the call site (i.e. within the second with) - the other is not set to the b , this would be contrary to the that GML works at other script calls... i.e. within a collision.

@rwkay rwkay closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Team Workload Aug 27, 2024
@YYDan YYDan removed this from the 2024.10 milestone Aug 27, 2024
@YYDan YYDan moved this from Done to Not a bug in Team Workload Aug 27, 2024
@rwkay rwkay reopened this Aug 29, 2024
@github-project-automation github-project-automation bot moved this from Not a bug to Triage in Team Workload Aug 29, 2024
rwkay pushed a commit to YoYoGames/GameMaker-HTML5 that referenced this issue Aug 29, 2024
* When a method call is made and the `self` is changed to the bound struct then set `other` to be the previous `self`
* If `new` calls a constructor on a bound method then  ensure `other` is set to the bound `self`, otherwise it is the `self` from the new callsite.
* Address feature request - YoYoGames/GameMaker-Bugs#7349
@rwkay
Copy link

rwkay commented Aug 29, 2024

Use this project for testing...

Bug-7349.zip

@stuckie stuckie moved this from Triage to Todo in Team Workload Aug 30, 2024
@stuckie stuckie added this to the 2024.10 milestone Aug 30, 2024
@rwkay
Copy link

rwkay commented Aug 30, 2024

After discussion with Kat we have revised some of the rules around handling other.

The central principle is that when the current self is changed as part of the runtime then other will become the previous self, until now this has only happened in 2 places

  1. As part of the with statement
  2. When new is called when the constructor is executed other is set to the self at the point that new was called (the call site).

To fit with the central principle we have introduced another point where other changes and expanded on 2 above. So the revised rules mean that other now changes when.

  1. As part of the with statement
  2. When a function is called as part of a bound method - other is set to the original self at the call site.
  3. When new is called if the constructor is just a function then as before other is set to the self at the call site, if the constructor is a bound method then other is the bound self.

We will make this change in 2024.10 - we expect the impact will be minimal (let us know if that is not the case)

@rwkay
Copy link

rwkay commented Aug 30, 2024

Added in 2024.10

@rwkay rwkay closed this as completed Aug 30, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Team Workload Aug 30, 2024
@KormexGit
Copy link

That new case sounds super useful!

@gurpreetsinghmatharoo gurpreetsinghmatharoo added the documentation Improvements or additions to documentation are required by this issue label Sep 2, 2024
@YYBartT YYBartT self-assigned this Sep 6, 2024
@YYBartT YYBartT removed their assignment Sep 18, 2024
@gurpreetsinghmatharoo gurpreetsinghmatharoo self-assigned this Sep 18, 2024
gurpreetsinghmatharoo added a commit to YoYoGames/GameMaker-Manual that referenced this issue Sep 18, 2024
@gurpreetsinghmatharoo gurpreetsinghmatharoo moved this from Done to Ready for QA in Team Workload Sep 18, 2024
@YYDan YYDan changed the title Incorrect other result when used inside of method functions In-Game: Add support for "other" to be the originating "self" when used inside methods Sep 19, 2024
@YYDan YYDan added feature request New feature (or a request for one) and removed runner-bug In-game bugs with the "GameMaker Studio 2" runtimes labels Sep 19, 2024
@mgeddesGM
Copy link

verified as of IDE v2024.1100.0.626 Runtime v2024.1100.0.652

@mgeddesGM mgeddesGM moved this from Ready for QA to Verified in Team Workload Sep 24, 2024
@KormexGit
Copy link

This appears to only be implemented in YYC, not VM, in 2024.1100.0.652.

Testing with the following code:

function test() constructor {
	draw = function() {
		show_debug_message(other)
	}
}

//on an object, create event
struct = new test();
//draw event
struct.draw();

In YYC, the message prints the struct:

{ draw : function }

In VM, it prints the object:

{ struct : { draw : function gml_Script_anon@39@test@Script1 } }

Only YYC Bug.zip

@rwkay
Copy link

rwkay commented Oct 8, 2024

Updated fix in 2024.11

@rwkay rwkay closed this as completed Oct 8, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Team Workload Oct 8, 2024
@gurpreetsinghmatharoo gurpreetsinghmatharoo moved this from Done to Ready for QA in Team Workload Oct 15, 2024
@scott-dunbar
Copy link
Collaborator

Verified across vm,yyc,html5 on all attached projects

IDE v2024.1100.0.646 Runtime v2024.1100.0.666

@scott-dunbar scott-dunbar moved this from Ready for QA to Verified in Team Workload Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation are required by this issue feature request New feature (or a request for one)
Projects
Status: Verified
Development

No branches or pull requests

10 participants