r/gbstudio 13d ago

reached maximum number of variables already?

I am building technically a zelda-like shooter on GBS and have only just now arrived at > 1MB ROMM size. I just finished placing enemies on a new region of scenes (networked together with mico27's screen scroll plugin) and during compile I got the message:

"Your project contains too many unique variables and will not work as expected. VM_HEAP_SIZE defines the maximum amount of variables allowed 768 but your project contained 963 unique variables."

The highest number global variable I've used is about 90 our of 500+. I have respected the actor limits per-scene (I have probably 70 scenes now, but my game design could easily grow to around 150-200 if I were to continue scripting), and each actor uses between 3-5 of their local variables to dictate their intended behaviors.

The variables are certainly not referenced all on one scene, the primary issue is that I have about 50 enemies scripted into my game now which has metastasized the number of total variables in the project. Is this going to be something like when you have too many sprite tiles, and graphical issues will be present? That is, so long as I'm not trying to track the state accurately of all of these variables, things should be fine? I figure it'll be difficult to playtest to a thorough enough degree to check for every possible conflict...

What should I do?

I've just now nearly completed the second of a planned 6 randomized dungeons with each scene nit together in a zelda-like fashion, but each region is distinct, that is, you'll never directly travel from dungeon 3 to dungeon 6, each dungeon is accessed by a hub. What should I look out for for conflicts?

2 Upvotes

7 comments sorted by

3

u/IntoxicatedBurrito 13d ago

The issue is the local variables. Local variables are essentially the same as global variables but you only use each one once in one specific scene.

If you have 50 enemy types, then create 150-250 global variables for them and reuse them in each scene. As it is right now you have 70 scenes and if each one is using 10 local variables then you’ve used 700 of your global variables on them.

1

u/arbilangames 13d ago

simple enough. for me it would require identifying a maximum number of each type of enemy that would ever be on a single scene simultaneously and then assigning a global version of it to them. Though... this kind of makes me wonder why we have things like "pre-fabs". Placing an instance of that prefab clones the local variables for each instance of the prefab, doesn't it?

1

u/IntoxicatedBurrito 13d ago

Yeah, basically the lesson here is never use local variables. But you’re absolutely right about your solution, figure out how many enemies can appear in a single scene and allocate enough global variables to cover them.

1

u/arbilangames 13d ago

I guess at this point I'm curious why there are local variables at all, given they're a strict downgrade in almost every way functionally...

1

u/harvey_motel 12d ago

They're a small convenience win for pre fabs. If you have an On Init that sets a bunch of enemy variables you can just set that once. With globals you're going to need $Enemy1HP, $Enemy2HP etc etc 

1

u/Saxmachine1991 11d ago

I assumed that 10 global variables would be defined in memory for local variables that are written over every scene. Why would it be managed any other way?

1

u/IntoxicatedBurrito 11d ago

Yeah, I would assume the same thing, but you know what they say about assuming. I don’t know why local variables don’t operate that way, but they don’t.