Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

GMLive.gml

Livecoding for GameMaker: Studio / GameMaker Studio 2 · By YellowAfterlife

[Fixed in 1.0.48+] Methods inside structs cannot read their variables without being directly referred

A topic by mrvictordiaz created Feb 17, 2021 Views: 413 Replies: 10
Viewing posts 1 to 4
(1 edit)

This throws an error under GMLive. Turns out that methods inside structs cannot read their own variables without being referred to first like in line 7, then reading it by with s.name instead of name or even self.name

self and other doesn't work correctly too I think

Any thoughts?

Developer(+1)

This one’s a head-scratcher! So function declarations inside an object literal {} are auto-bound to it, but it’s not clear how does it know to do that - even if you do

var f2 = function() {};
f2 = method(undefined, f2);
var f3 = function() {}
var obj = {
	func: function() {},
	func2: f2,
	func3: f3,
}
trace("f1", method_get_self(obj.func));
trace("f2", method_get_self(obj.func2));
trace("f3", method_get_self(obj.func3));

that does not change ownership of func2/func3.

Developer

I have finally fixed this in 1.0.48+ - I couldn’t figure out what exactly GameMaker itself does, but GMLive now reproduces this behaviour.

Gotcha, thanks!

(1 edit)

Hmm I think other isn't working correctly this time around. Under GMLive, referring to other yields an incorrect reference vs. without GMLive. Any quick workarounds for this?

Edit: Yup other was never working in the previous build. Self was fixed however.

Developer

Can I have a small snippet for reproduction? I’m pretty sure that I’m doing with (new_self) so that shouldn’t be breaking too easily

(1 edit)

Add show_debug_message(other); right under line 8 on the snippet above

Output without GMLive (the expected output):

 {  }

With GMLive:

{ live:context : "gml_Object_objGolem_Step_0", live:function : "objGolem:Step_0+1+1", live:self : { name : "Alex", greet : function gml_Script_vm_group_call_on_func_literal_lf } }

Running on the step event of a fresh new object named "objGolem"

How did you fix self, speaking of which? Could be related to that. I may be able to help look into it with some points of reference.

Developer(+1)

This new issue is caused by self inside a bound method reasonably being the self from method call, but I have not rolled out a new version yet since I found more things to fix.

You can fix this specific thing by going into GMLive_vm_callvm_group_call_on_func_literal_lf and changing

live_custom_other=self;

to

live_custom_other=other;

You rock.