ZeDuval
Member
UPDATE: v2.0.3; New:
- Last version included as a rollback-possibility
- Supports an unlimited amount of methods now, instead of 15 like before
- Supported number of arguments increased to 20
Object Method enhances the otherwise object-oriented approach of Gamemaker with the possibility to define and then invoke named methods(functions), that are bound to objects, fully functional with up to 20 arguments and a return value.
In the Create - Event of the object obj_abc use...
Code:
method_init();
Method1 = method_def();
Method2 = method_def();
In the User Defined 15 - Event (Add Event > Other > User defined > User 15) you can either have one "Execute Code"-Block like this...
Code:
/// all object.Methods
if method(){
show_message("Method1 "+A0+A1);
}
if method(){
RETURN = A0 + A1;
}
Code:
/// Method1
if method(){
show_message("Method1 "+A0+A1);
}
Code:
/// Method2
if method(){
RETURN = A0 + A1;
}
Within the object itself you can then use...
Code:
method_invoke(Method1,"with"," arguments");
var ret = invoke(Method2,1000,337);
show_message(ret);
To invoke a method from another object that has a reference-variable to obj_abc use...
Code:
abc = instance_create(0,0,obj_abc);
method_invoke(abc.Method1,"with"," arguments");
Code:
method_invoke_obj(abc.Method1,"with","arguments");
Code:
method_invoke_obj(obj_abc.Method1,"with"," arguments");
Special thanks to elementbound for brainstorming af and the suggestion to use only UE15 and to provide an unlimited amount of methods.
Tested for following export modules: Windows, Windows(YYC), HTML5.
Last edited: