• 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!

Asign funtions in structs

Hello !

I would like to declare a function in a script and then assign this funtion to a variable in a struct to call that function. Is that possible and if yes how ?
Here is a little example :

GML:
function message() {
    show_debug_message("this is a message");
}

function struct_with_message() constructor {
    msg = message();
}
Of course that way "msg" gets the output of the function but doesn't become the function.
Any idea ?

Thanks :)
 

Roldy

Member
Hello !

I would like to declare a function in a script and then assign this funtion to a variable in a struct to call that function. Is that possible and if yes how ?
Here is a little example :

GML:
function message() {
    show_debug_message("this is a message");
}

function struct_with_message() constructor {
    msg = message();
}
Of course that way "msg" gets the output of the function but doesn't become the function.
Any idea ?


Thanks :)
GML:
function message() {

    show_debug_message("this is a message");

}



function struct_with_message() constructor {

    msg = message; // No paranthesis

}
 
Top