Hello,
I am kinda new to Gdevelop and I wanna make a game, which will need a huge amount of global variables, because I will need them in almost all scenes. Like an array with 800 structs, which contain 30 variables each. Can I do it in global variables or would it cause performance issues? And if there would be performance issues, what would be the alternative to prevent them?
1 Like
What are you creating that requires so many variables? Perhaps there’s an alternative way.
1 Like
Something like Pokemon… Each Creature that exists in the Game has its own Stats, so there has to be anything that contains all of them.
I don’t know at what point a variable of that size would cause lag or worse.
I don’t know if it would be better to use a array or use object structures that are loaded as needed from storage or a Json file or database or some other external storage method.
I would assume you could have 1 array of structures with the default values for each character type. You could then either add it to another array or to the object itself as needed. A bit like object culling.
The object variable approach would help to keep things light. Only the applicable variable would be in use at a time.
I asked a Chatbot and it suggested using efficient and minimal structures and variables. It also suggested using compression. I’m guessing that even some sort of shorthand would help. Like using a letter or 2 to represent longer words. Or maybe storing the data as a comma delimited text. Either as Json or just the data. You could then create the structures as needed.
This is all just me thinking outloud. I’m sure there are people with more knowledge that will chime in.
It is difficult to tell what alternate solutions you, without knowing more about your project. I don’t know though if 800 structs with 30 variables each is thaaat huge. That’s about 200 Mb of Ram.
However it depends whether you want to read every piece of data every frame…
I’d say, your best bet would be to try. At least that’s what I’d do. For example if you don’t have those data ready yet, write a “repeat” event that would create that table with fake data (as a subevent of a “At scene startup” event), and see how it behaves.
It is like a Pack Opener… You can draw the Packs and there you need the data. You need it in the beginning of the program to calculate prices of the packs and you need it in fights… There is nothing with time or frames, just buttons reacting on clicks
I’d say : try with generated date as I explained above. That’s just a few line of code to do that. And see how it goes.
Then if you see that the memory usage is too much and causes issues, you could split that data in multiple files, which you would load only when needed.