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

GML Best way to organize sets of values outside an Object?

S

Skye Veran

Guest
I'm having trouble verbalizing this but I'll try to be brief.

I'd like to have your opinions on the "best" way to organize sets of values in Game Maker for in-game "actions" a character might make. As an example:

Action: Shoot
Associated script (contains all code for the action itself): scr_shoot
Cancellable into actions: Jump, Roll
Cancellable frames: 10-20

The actual code for executing these actions I don't really need help with (yet). I just want to know how to put these details into one "object". I can't really make an actual Object though, as it would have to create an instance of itself to refer to these values.

Alternatively, the scr_shoot script might be able to contain these values by adjusting variables during its execution. I don't know if this is what I want yet.

I hope this makes sense. It's possible I'm thinking about this entirely wrong, in which case any input would be helpful. Thanks for reading.
 

NightFrost

Member
Well, a player actions system would be usually built around a state machine, with the relevant variables defined in the player object's Create event. The cancelling, and in general which state can switch to which, doesn't really change so I would build that straight into the state machine's structure.
 

chamaeleon

Member
I'm having trouble verbalizing this but I'll try to be brief.

I'd like to have your opinions on the "best" way to organize sets of values in Game Maker for in-game "actions" a character might make. As an example:

Action: Shoot
Associated script (contains all code for the action itself): scr_shoot
Cancellable into actions: Jump, Roll
Cancellable frames: 10-20

The actual code for executing these actions I don't really need help with (yet). I just want to know how to put these details into one "object". I can't really make an actual Object though, as it would have to create an instance of itself to refer to these values.

Alternatively, the scr_shoot script might be able to contain these values by adjusting variables during its execution. I don't know if this is what I want yet.

I hope this makes sense. It's possible I'm thinking about this entirely wrong, in which case any input would be helpful. Thanks for reading.
You could use an object for abstract data instead of things that appear on the screen if you wish.
Script to create a new data instance
Code:
var data = instance_create_depth(0, 0, 0, obj_data);
instance_deactivate_object(data);
return data;
Make a new variable data instance and add some information to it.
Code:
data = new_data();
data.action = shoot;
data.script = scr_shoot;
data.cancellable = ds_list_create();
ds_list_add(data.cancellable, jump, roll);
data.frames = [10, 20]
Or you could use ds_maps.
Code:
data = ds_map_create();
data[? "action" ] = shoot;
data[? "script" ] = scr_shoot;
data[? "cancellable" ] = ds_list_create();
ds_list_add(data[? "cancellable"], jump, roll);
data[? "frames"] = [10, 20];
Best is really in the eye of the beholder. Most important is probably to be consistent and have a well-defined framework for data in general that makes sense to you.

Of course, as soon as you introduce ds_whatever data structures here (like the list of "cancellable" actions), you'll need to keep track of which entry contains such a thing (back to consistency and well-defined, etc.), so that you can destroy it when you destroy the instance or map containing it (unless you mark lists as lists in the ds_map, so that it takes ownership of it).
 
S

Skye Veran

Guest
You could use an object for abstract data instead of things that appear on the screen if you wish.
Script to create a new data instance
Code:
var data = instance_create_depth(0, 0, 0, obj_data);
instance_deactivate_object(data);
return data;
Make a new variable data instance and add some information to it.
Code:
data = new_data();
data.action = shoot;
data.script = scr_shoot;
data.cancellable = ds_list_create();
ds_list_add(data.cancellable, jump, roll);
data.frames = [10, 20]
Or you could use ds_maps.
Code:
data = ds_map_create();
data[? "action" ] = shoot;
data[? "script" ] = scr_shoot;
data[? "cancellable" ] = ds_list_create();
ds_list_add(data[? "cancellable"], jump, roll);
data[? "frames"] = [10, 20];
Best is really in the eye of the beholder. Most important is probably to be consistent and have a well-defined framework for data in general that makes sense to you.

Of course, as soon as you introduce ds_whatever data structures here (like the list of "cancellable" actions), you'll need to keep track of which entry contains such a thing (back to consistency and well-defined, etc.), so that you can destroy it when you destroy the instance or map containing it (unless you mark lists as lists in the ds_map, so that it takes ownership of it).
Thanks for the ideas, these are the kinds of things I was thinking of!
 
Top