Bart
WiseBart
Hi all.
I'm trying to do a seemingly simple thing using the new structs in GM2.3:
Where struct is some struct and instance is a method of that struct that is tagged with the constructor keyword (let's say a "constructor method").
The important thing is that the instance needs a reference to the struct but that seems to be hard to do using the current syntax.
Is there a way to get a reference to the struct of such "constructor method"?
self cannot be used since it becomes a reference to the new struct when using the new keyword.
Obviously the easiest to fix this would be to do it like this:
i.e. make a "normal" method return a new instance and manually set its creator.
I'm wondering how everyone else is doing this.
Are there any things that I'm missing here?
I'm trying to do a seemingly simple thing using the new structs in GM2.3:
GML:
/// Convenient macro definition
#macro log show_debug_message
/// Function definitions in script asset
function ins(creator) constructor {
self.creator = creator;
log(self);
}
/// Struct definition
struct = {
_method: function() constructor {
log(self);
},
instance: method({creator:self}, ins), // It seems like the reference to the struct parameter is lost when the method is called as a constructor using the new keyword
instance_the_other_way: function() {
var new_ins = new ins(self); // Call the global function
}
}
new_instance = new struct.instance(); // creator = undefined, this is the one I'm trying to get to work
inst2 = new ins(); // creator = undefined
inst3 = new ins(struct); // creator = struct, but obviously we passed this manually
The important thing is that the instance needs a reference to the struct but that seems to be hard to do using the current syntax.
Is there a way to get a reference to the struct of such "constructor method"?
self cannot be used since it becomes a reference to the new struct when using the new keyword.
Obviously the easiest to fix this would be to do it like this:
GML:
new_instance = struct.instance_the_other_way();
I'm wondering how everyone else is doing this.
Are there any things that I'm missing here?
Last edited: