New unified variables and variables declaration in GDevelop 5.4

I feel like need to take in to consideration, there are 2 type of beginners. The one who wish to learn how to do everything the correct way and don’t mind to take the necessary extra steps and time, and there are those who just want to and need to see results immediately to stay motivated. I was the latter and the old system didn’t stop me from learning to do things the correct way but allowed me to just have fun in the process. No other engine offered this freedom.

It is not about being easy to understand but easy to start with. Everyone has different experience and started game dev with different backgrounds. When I started my background was empty completely and I disliked the way other engines forced me to do things in a very specific way forced me to learn concepts before I was able to do anything. I loved the way GDevelop allowed me to just play around it just worked.

This is subjective and wrong in my personal experience.

When i was learning how to use variables in GDevelop, i thought you had to declare every single variable, and i found this a pain from day one.

It didnt help me understand it any more or any less, if anything, i avoid having to use variables because i just didnt want to constantly have to clean them up since i was just experimenting.

Then i checked out an example about inventories and saw that even tho there was loads of events with variables, there was no variables on the variable sheet, this blew my mind.

I was left wondering how the heck this project had no declared variables but everything worked with event variables…

Thats when i leaned you didnt have to declare them, and simply add them in on events.

This was so freeing, and made me use them more and more, learn more way of how to apply them since i didnt have the extra steps to go trough… and id say that worked pretty well.

Now i have a pretty good grasp of how to work with variables thanks to that.

So again, i dont really get how a beginner in GDevelop will benefit from this.

GDevelop would create the variable and give it a default value of 0. Because variables were loosely typed it could be taken as boolean (false), number (0) or string (“0”).

1 Like

So it does already declare it right? thats what you mean by create?

I know they get created, but not as their proper types until they get used, its sort of like a placeholder,

for example, i made a Scene Boolean called “UNDECLAREDTest”, set to False.

This is what shows up untill i actually do something with that variable

After its used, the type changes into Boolean with a regulard boolean value.

…either way, if this works, why does it need to stop?

Honestly ill just stop asking at this point since i dont think theres any answer other than because thats how its supose to be.

This is how i would solve current problem

It would not penalize ones that do not want to declare their variables
While it would help ones that are into declaring their variables

If we want convince users they should declare their vars i say this is right path
Where we do all of this in same exact window we start to use new var
No one gets harmed everyone benefits from it
Nothing is taken away something is given to everyone

You have no idea how wrong you are
Soon what will happen is that ppl will come here and on discord asking where is THAT option
Because they see something else on screenshot/video on how to set up variable from what they have in the engine
I am not fortune teller i cannot see into future
So how i can be so sure?
Cause every week i answer at least one question like
Where is action to change animation / fire bullet
And we get that there cause over course of updates naming changed and i say it is a good thing
Since now names make more sense
Yet it create confusion among users who do not take into consideration that something could get an update

And just wait will same thing will start happening to every single tutorial that included setting up vars

I already said it somewhere but i as dyslectic should be all in for new change
Yet i am not i never had any big problem with previous system
Neither i ever seen any1 ask for variable system to be updated changed in a way that we need to declare all variables
I do not want to take away declaring variables i want choice of not declaring them not being taken away from us
In fact i want better system i made post about it which is in my above message
Which would streamline the process for all of us not penalizing any1

1 Like

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 not 1 + 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 :wink:
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 :slight_smile: 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.

3 Likes

Is the “about 2 clicks” still to come? Currently we need to click on the “Add or edit variables…” option, select the correct tab, and then enter the variable name and select type. I would have thought with the changes that the initial drop down (under the “Add or edit…”) would have options like “Add as scene boolean”, “Add as scene number” etc. This would be quicker still.

Be honest and ill shut up about this for good…

How many complaints did you actually get about this? Not the update, i mean complaints that lead you to change variables?

I dont remember seeing anything on the forums or any mention of it, did people really mess up that much and complain directly about the engine?

What happened?

Or is this a “just in case”?

Thats the part i really dont get… i

Tell me wouldn’t that solve the issue?

Man i wish i could explain what i have to say about this way better… but check this out.

GDevelop did not support you using undeclared variable in expressions, this makes sense, and as far as i recall, that was my experience, but…

If you add an undeclared variable in an event, GDevelop now handles that variable as if its declared and does allow me to add it inot an expression.

THIS RIGHT HERE!!

This is why its always felt natural to work with undclared variables in the event sheet, once i add it onto the events, that variable feels declared, in fact even the fact of writting the variable down, feels like your declaring it and since the engine then acknowledges that variable in expressions afterwards, it just feels right.

All that without ever seeing the variable page, this is what i ment about how it felt like the way forward.

It does seem like your doing the “professional” step.

…and when i have a reason to declare variables, i still do it with no issues, their usually globals, like when i need a coin counter, or an item counter, or player level, stuff like that.

But simple scene variables that are used to lock key presses or open menus, like booleans, i have no need for all taht, i just “declare” them on the events.

I did still learn the importance of “declaring” the variable, and making it show on my “code” in the events, i just didnt do it the proper way…

I really hope you read that and that it made sense…

Yes (still to come), there’s been a few mentions of the need for (and desire) to add a simplified UX/UI for rapid creation of declared variables by 4ian and the devs. It is not available yet.

2 Likes

I’m not a fan of this decision. I feel like I’m being punished because other people are stupid. Curiosity about one of the comments requires me to ask, if I update I can no longer have a global, scene and object variable with the same name?

I just said what the founder and the other full-time devs say, so…
And ya I helped many beginners on and offline to get started with GD, years before you were here🙃

Yes they will, because there has been a change. What I said is that there are technical advantages to declaring them. And they are working on making them easier to declare. With just one click on undeclared ones, I think.
But we’ll see, there is a hint and the variable editor button is only 1 centimeter away from the field, 99% will find it on their own. 01
It is normal that years old screenshots may no longer be up-to-date, but that shouldn’t prevent any innovation. Examples and official videos will be updated.

But hey it fully doesn’t matter what I think about it, I didn’t want it too but I don’t think the world is going to end because of that, other changes and the lack of the option to turn it off optionally were more annoying for me.

Sometimes I wish there was more discussion and voting before things are finally implemented, but in the end it is the decision of those who do the work.

2 Likes

I have been using Gdevelop for a long time, and in my particular case, it is a very big job to declare each variable. Added to that, I have many variables with the same name but for scene, object, global, etc. I prefer the previous system (I feel like I have more control over what I do). I really don’t like having to spend a ton of time “fixing” things that aren’t “broken” in my game, with the result being simply the same thing I had before, but I imagine that the idea is not to return to the previous system, so I propose some intermediate to make it easier for those who have larger projects to migrate to the new system. I suggest implementing some quick way to detect all the variables present in a scene (or external event), such as a scan, to be able to declare them with few “clicks”. Also, find out which ones have the same name, to suggest changing them.

I’m interested in understanding this. Would there really be a difference in the performance of Gdevelop games with this system?

Hey there,

I think the new system is a BIG improvement to GDevelop. Here’s why…

Having all the variables declared in the project means having total control over these variables. This links the events with the declared variables so that any change is universally updated anywhere the variables are referenced. Similar to how objects work.

YES it takes few extra seconds to declare each variable.

BUT it eliminates having to type the long expressions and saves a lot of typos in the code. Fixing one simple error in the code can take much more time than the time it takes to declare or edit a variable.

Having the “Freedom” to be able to use undeclared variables made me work the wrong way. It’s a NIGHTMARE to change a variable in a big project with lots of scenes and external events, by going through each events sheet and Search / Replace expressions.

But having this “Limitation” makes for simpler and more streamlined workflow using variables. This forces the use of variables in a more responsible way. Which in the end makes the code easier to read and navigate through, and the project will be more organized.

I had different feelings about this change at first, because I was used to a certain workflow for a long time and the change caught me off guard. And I think a lot of developers are feeling the same way right now.

But after trying the system more and going through the discussions, I understand now the importance of declaring variables and that this is the correct way of doing things!

I’ve been using the engine since GDevelop 4, and I learned a lot and I will continue to learn from the experts in the team and from the community. I also saw how GDevelop evolved since then with every major update.

This variables system is intuitive and will only get better over time. It makes understanding variables simpler, faster and more fun to use.

This is just my opinion and sorry for the long post.

I believe the GDevelop team made the perfect decision!

Many thanks to everyone involved in continuing to make GDevelop more and more awesome!

1 Like

Perhaps. I myself am still not sold on the idea. Possibly because I already listed important variables in their appropriate variable pane so any benefit of doing so now is no more benefit than I had already but with the added ability to take an undeclared variable, say TempVar, and use it as a place to put a json, convert it back into the same TempVar as a structure, erase the structure by turning it to a number etc. I didn’t gain a thing.

Also I liked the long expressions. I made an impressively long expression once when I had first been using GDevelop a few months and I was so proud of its ungainly size I rushed to the forum to share it. I remember Keith I think pointed out that I could have shortened it by doing some of the calculations independently and then using the resulting variables in the expression instead of my verbose and masterful precious.

I am all for people dictating how I do my workflow to make it simpler and more streamlined for them, when they pay me. On my dime, I prefer to do things my way and trust me, when something is quicker and easier I latch on to it because I am lazy and my brain just looks for things like that.

So I for one am pretty disgusted with the change, but it is actually not the first change I have been disgusted with. It really doesn’t matter to me because I love GDevelop and will continue to support it. There is no game engine in the world that is not going to make some change that disgruntles some users but in the end you have to look at majority benefit and the future of the engine. I think they’re being great about the gentle timeline of this whole thing so that people can get migrated over, not just creating a new system and breaking everyone’s old projects outright without ever giving anyone a hint.

I sit on discord trying to solve other ppl problems
Sometimes it is way easier to me to just set up events send screenshot and link to preview of my project to ilustrate+prove it works

This already happened to me but it will be same story for every user for which i try to solve their problem

2 days ago user on discord ask how to make something happen on increments of a number
For sake of simplicity lets say each 5 so at 5,10,15,20,25,30 and so go on

My best idea is to use modulo expression on some variable
(Modulo loops around some number so imagine you have variable seconds and if you mod seconds to 60 then when it should hit 61 it will not go to 61 but instead start counting again from beginning)
So he had variable called Combo
Using compare two numbers condition he could simply go with
mod(Variable(Combo),5)=5
And now in action he could do whatever he wants
And it did not work and it was because my mistake
I forgot module accounts for 0 so when i told him to put there ,5 what it did was go 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 since that’s 5 digits including 0
I did not realize that so i went to test it in my project and show him it is working
And then i found i forgot about that 0
So proper expression would be mod(Variable(Combo),6)=5
Now it would go 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 since that’s 6 digits including 0 and it will hit 5

To do that i needed to declare variable just to test it out in my project in which i do not need that variable
I did say sorry for my mistake and showed him how it should be done

Now i needed to go back to my project and delete manually that declared var which my project won’t use / don’t need
Just so i do not litter my project with random vars

Variable update added me 2 tasks which takes up time if i want to provide that kind of help
There is no argument how long it takes it is few secs to declare and delete vars
BUT each time i gonna help someone this way i gonna need to take 2 additional steps
And i cannot say that my workflow because of this update got better the same way you can
Declaring variable in above scenario did not give me anything and only made me need to delete declared variable in addition to deleting events after i did make visual presentation for someone

And i or any1 here is not asking “please remove declaring variables”
Far from it
Cause you see old system still works so projects using old system do not break
I can copy or pre made variable of each type put it into disabled event group and just copy paste them when i need them
Either way i need now take additional steps each time when i try to solve problem for someone on discord or even here on forums
I won’t die from it but my workflow did not got better

So me or other users are not in need of taking away declaring
We ask for streamlined way declare vars or a easier way to use not declared variables

If new system did make your workflow better then good for you
But consider not all of us do what you do and use gdevelop in same exact way as you do
So for some of us new system can cause more problems than it solves
Where in most cases we did not have problems with old system

I agree with ddabrahim, Lucky-j and ZeroX4 here. Declaring the variables in advance is apparently the best way, but I believe that the user should have the freedom to decide whether they want to do it this or another way, even if the latter is not considered to be ‘good practice’.

It is not only easier for beginners, it also makes it faster to stitch something together for testing or sharing. I see it as a strength that you could do something unoptimized in Gdevelop and it would still run.

Reading through the posts in this topic gave me a flashback to this one 2 years ago, when timers suddenly had to be declared in advance.

Obviously everyone gets used to a new system after spending some time with it, I just don’t believe that those changes make Gdevelop necessarily user-friendlier or faster to use - which is one of the hooks on the webpage to try the engine.