Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

how do you update structs in a script?

A topic by DEEP0 created Jan 20, 2025 Views: 278 Replies: 8
Viewing posts 1 to 3

i have a script with a bunch of structs in ( my game data script  ) and i wanna be able to change values in it & for it to update. putting any of the live call functions in the script gives me an error .

Developer

Depends on what’s in the script!

If it’s just struct assignments that are done once on game start, you’d want to wrap them in a

function some_init() {
    global.a = { ... };
    ...
}
some_init();

because global script init is a little quirky to resolve from GML.

Then you can use live_code_updated to re-run the (updated) script when a new version is loaded.

thanks for the response!  i've wrapped my array in a function:

function enemies_struct(){       
    global.enemies =     
     {           
     ...      
     }  
enemies_struct();

but i'm struggling to wrap my head around the live code updated function. how would i format the function & where would i put it? thanks! 

Developer

Like this, you can add it in the end of GMLive’s create event or anywhere else that executes after live_init

live_code_updated = function(_name, _display_name) {
	if (_name == "enemies_struct") enemies_struct();
}
(3 edits)


sorry to keep bothering you, but I just cant get it to work. i have:

live_code_updated = function(_name, _display_name)   
{          
    show_debug_message("Reloaded " + _display_name + "(" + _name + ")");           
    if (_name == "enemies_struct") enemies_struct();   
} 

in the GMLive create event, and then :

live_code_updated("enemies_struct", "enemies stuct");

in the step event.  I get "Reloaded enemies stuct(enemies_struct)" in the output, but when i change a value in the array it doesn't affect the game.

just for reference, this is what my function looks like, it's a struct complied of arrays:


Developer

You should have a live_call in the enemies_struct! Won’t get changed otherwise

I've already tried that:


but I just end up getting the error message:

___________________________________________

############################################################################################

ERROR in action number 1

of Create Event for object <undefined>:

global variable name 'live_request_guid' index (104394) not set before reading it.

 at gml_Script_live_call (line 12300) -               if(live_request_guid==undefined){

############################################################################################

gml_Script_live_call (line 12300)

gml_Script_enemies_struct (line 165) - if (live_call()) return live_result;

gml_GlobalScript_GameData (line 356) - enemies_struct()

🤔

Developer

Ah, I suppose your script runs before GMLive’s initialization? You could make it

if (!live_enabled) enemies_struct();

in the script and add

if (live_enabled) enemies_struct();

to the end of obj_gmlive’s Create.

Or rename the “GMLive” script to “__GMLive” so that it runs before the rest. Kind of silly but that’s the world we live in starting with last year’s updates.

that worked leTS GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

thank you for not giving up on me mr.afterlife!

you were a great help, thanks so much😸