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

SOLVED How to handle Object Variable Definitions for Script Assets now that Scripts are collections of Functions?

KMVegas

Member
With 2.3+ Object Variable Definitions, we can still choose Script Assets as before, but we can't select a Function from that Script. Is there a way to work this out, or is there really no point in selecting Script Assets as Variable Definitions anymore?

For example, in my pre 2.3+ workflow, I would have a Parent with Variable Definitions for scripts, such as EntityInit, EntityUpdate, etc. and execute them where appropriate. By default, they'd be set to noone. Then, in the Child Objects, I would override with the appropriate script assets, such as PlayerInit, PlayerUpdate, etc. and I've yet to figure out how this is going to work now.
 
In parent create
EntityInit = undefined;

In child create
EntityInit = method(self, PlayerInit);

When you call the function later on
if (!is_undefined(Entity.EntityInit)) { Entity.EntityInit(); } or with (Entity) { if (!is_undefined(EntityInit)) { EntityInit(); }}
 

Mr Magnus

Viking King
Where you used to reference script assets you can reference the functions directly instead for the same effect, so you could do

GML:
//Parent

action = undefined;

//Parent step (f.i)

if(!is_undefined(action)){
    action();
}

//Child

action = process_input; // In some script you have the function process_input. Reference the function.
for DND you may not be able to easily select them from a drop down list, but you can type in the function name yourself and it will work.
 
Last edited:

chamaeleon

Member
With 2.3+ Object Variable Definitions, we can still choose Script Assets as before, but we can't select a Function from that Script. Is there a way to work this out, or is there really no point in selecting Script Assets as Variable Definitions anymore?

For example, in my pre 2.3+ workflow, I would have a Parent with Variable Definitions for scripts, such as EntityInit, EntityUpdate, etc. and execute them where appropriate. By default, they'd be set to noone. Then, in the Child Objects, I would override with the appropriate script assets, such as PlayerInit, PlayerUpdate, etc. and I've yet to figure out how this is going to work now.
Perhaps you can work around it by having your variable definition be a list, and add each function to the list.
gms2 variable definition.PNG
If you don't want that, you can just type the name of the function an Expression, but no automatic selection discovery like browsing for it..

And I realize that the list method is less than useful if there is only one function that would fit a particular variable name.
 

Nidoking

Member
Functions may not show up as assets, but you can still just type the name of the function. Make the variable an Integer.
 

KMVegas

Member
Thanks for the feedback, friends. You've answered my question and presented some viable alternatives, so I'll mark this as solved.
 
Top