• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

"Methods"/"Member Script" functionality improvement

S

Salvakiya

Guest
Was wondering how any of you would improve on this.

I have an object called oMethod. this object is a parent object for all objects I wish to use my Method system. I also have one script called method(name, *args);

here it what it looks like


Code:
///BEGIN NO TOUCH ZONE
//method arguments
mInput[0] = 0;
mReturn[0] = 0;

//method inits
method_assign = ev_user0;
method_init = true;
for (i=ev_user0; i<=ev_user15; i+=1){
    event_user(i-10);
    method_assign+=1;
};
for (i=ev_user15; i<=ev_user15+11; i+=1){
    event_perform(ev_alarm,i-(ev_user15));
    method_assign+=1;
};
method_init = false;
//END NO TOUCH ZONE

Code:
///method(name, *args);
for (i=1; i<argument_count; i+=1){
    mInput[@i-1] = argument[i];
};

if argument[0]>ev_user15 {
    var ev = argument[0] - 26;
    event_perform(ev_alarm,ev)
}else{
    event_user(argument[0]-10)
}
mInput = undefined;
mInput[0]=0;
return mReturn;

after creating this object... any children just need to use something like this in their alarm/user events
Code:
/// @description damage_life(amount)
// YOU SHOULD PLACE NAME IN DESCRIPTION
// AND ASSIGN THE NAME AS A NEW VARIABLE
// IN THE INIT BLOCK BELOW
/*
    use mInput array for arguments
    use mReturn array to return values
*/
if method_init == true then {
    //METHOD_NAME = method_assign;
    //the name of this variable... damage_life for example... should be in the
    //description at the top of the "method"
    damage_life = method_assign;
    exit;
};

///method code goes here

this allows you to do have "scripts" or "methods" inside your object themselves... the return values are saved in mReturn array. you unpack arguments into the script using mInput.

It is a bit messy as I just threw this all together. I was wondering in what ways you think it could be improved.

example setup of method in any user_event or alarm event
Code:
/// @description damage_life(amount)
if method_init == true then {
    damage_life = method_assign;
    exit;
};

//damage object
life-=10

//lets show how to return... why not
mReturn[0] = life;
example call of method
Code:
var arr = method(damage_life,10);
show_debug_message(arr[0]);
Also keep in mind when using this as it stands now... you cannot have any alarms or user events already inside an object. it is designed to run each event on object create to define the "method"

I ran this in GMS2 and it works fine... Should also work in GMS1
 
Top