To give everyone the context on the technical reason why we can’t just say “undeclared variables can still be used with the new system” is because, when you use the unified, single action to change a variable, we can’t know where the undeclared variable should be created (do you want GDevelop to make a global variable? A scene variable? Is it a local variable to your event?) nor the type (but this is less of a problem, but still - allowing this kind of dynamic stuff reduce the margin we have to do performance improvement, by accessing for example directly the variable in memory rather than relying on its name).
Of course, we could do something “in between”. When the variable is declared, you use it and when it’s not declared, then GDevelop could assume it has to create a scene variable… which can create all sort of problems:
- this increase again the “mistake-prone” aspect (oops, I entered a capital L instead of a lowercase… how comes GDevelop don’t prevent me to do such a basic mistake?? => a new user could as well be furious about this “useless freedom GDevelop is giving that is biting me hard”)
- this is hard to explain and document “so it’s a scene variable but hey if you want it to be a global variable well you have to declare it.” “This is explained in the documentation but of course nobody read it”
- if someone declares a global variable with the name, and rename it, should we rename the actions/conditions made before the global variable was created?
- we can’t support - and never supported - undeclared variables written directly in expressions. It’s hard to understand why you could write
1 + DeclaredVariable
but not1 + UndeclaredVariable
.
This will create in our view more issues than solving this. Especially once we’ve polished the UX and declaring a variable is ~2 clicks, this could be seen as a net negative to allow you to use undeclared variables. This is why we decided against this extra complexity (because yes, this will be more complexity - in addition to still supporting all existing games with undeclared variables, as we would never break compatibility with previous versions).
Another note, I’ve read some arguing that “GDevelop tries to be too beginner friendly” and this could be seen as “dumbing things down”. I think this is the contrary: most professional game developers would be worried to see that undeclared variables in GDevelop are possible. It’s almost an heresy
They develop large scale games, where they must ensure their code is robust: variables are properly used with their right type, there is no obvious mistake, and GDevelop can create the most efficient code because it knows about what variables you’re using.
So this is actually moving toward more professional usage because this make GDevelop closer to good programming conventions (your game designer won’t break your level because they mistyped a variable. In a team this is really important.).
Note that if you don’t like all of this… you can use a structure Create a scene variable called “SceneVariable” and use it as a structure where you store any variable with any name.
This is perfect for dynamic situations. But in most cases, declaring a variable is the way to go and hopefully won’t take long, and will even be faster in the future.