How to use structure variables?[SOLVED]

My game features a weapon system which allows the player to pick up various weapons and use them. There are different properties for each weapon, such combo set and attack speed, and these are stored in the variables of each weapon. When a weapon is picked up, these will b loaded into corresponding global variables and written into storage, but I find this a bit inconvenient. I figured I can make this more neat by using a structure variable called “weaponinfo” and make the other variables its child variables, but I can’t find a way to load the structure variable of an object into a global variable. I doubt if it is possible, but I still want to optimize this part of the code since picking up weapons will be frequent in my game.


Also, will the performance of the game drop if the storage is accessed frequently (almost once every second in the game) ? Will it be better to use global variables and only loading stuff when exiting or entering the game?

JSONify the structure to save to storage, and parse from JSON to variable to load from storage. Here’s a link explaining how to do this (note, it was written with the previous variable expression, but you’ll get the idea).

Thanks! It worked! I’ll try optimizing other stuff like inventory using this method as well.

Why all of this variables pro :scream:

This is why.

1 Like

Well this is what happens when a project gets too big. It’s just torturing to manage them all.

1 Like