I found a few threads with a similar title, but none of them have an answer. I have a simple scene. There is text on the scene called text_point and I have the variable ‘actionPoints’ set to 10. I want the variable to decrease by 1 each time the logo is clicked. But the variable displays 0 from the very beginning. How do I make it display 10?
I will have mercy on your soul pointing out your mistake up front
Where it is more complicated than that
You are checking scene variable called actionPoints ← one s
While you are changing GLOBAL variable called actionPointss ← two ss
BTW you are adding to that variable not subtracting
But below you have wall of text of what you did exactly and why you should not
Before we had variable update where we did not need to declare variables but they would auto exist as soon as you use them in events
We needed to reference them in events as
Object → Player.Variable(HP)
Scene → Variable(HP)
Global → GlobalVariable(HP)
Which lead into issues like someone write Hp And was checking HP or hp
And was just like you wondering why it was not working
While we had separate actions and conditions for all 3 types of variables object/scene/global
BUT for sake of compatibility old system was left working so old projects would still work if loaded in newer version of gdevelop
So you still can call your variables same way as i described above
NOW we call these variables as
Object → Player.HP
Scene → HP
Global → HP
Where i think you can’t have HP both as scene and global var at the same time
Actually i need to check that but whatever
Anyway we have icons now next to variables showing us is it object/scene or global var
While we have single action/condition for scene/global variables
And we need to declare our variables which now are references
It means that same as object they need to 1st exist
For example you made object and called it Bulletzor
Now in events you try to reference Bullet
And you get red text cause that object does not exist Bulletzor does Bullet does not
So its easy to avoid such mistakes and you can select your object name from list
So looking at your screenshot you have there actionPointss GLOBAL variable
While in text object you are trying to reference SCENE variable using old system
Where at the same time your global variable is called actionPointss ← two s Pointss
And scene variable is called actionPoints ← one s on end and that is one you try to reference in text object
That is why you should reference your vars as
Object → ObjectName.VariableName
Scene → VariableName
Global → VariableName
Not throwing into mix old system
In my example, I am referencing a global variable called testing. At the beginning of the scene I set the value of that variable to whatever I like. If you have a scene variable and global variable with the same name (and I would recommend you don’t), you can use ToString(GlobalVariable(testing)) to be sure you are targeting the global one. In my example I only have one variable called testing and it is global. If I also had a scene variable with the same name the expression ToString(testing) would target the scene one.
The event that updates the text object should not be in an At the beginning of the scene event if you want it to run constantly. Events with the At the beginning of the scene condition will only run once, when the scene loads.
You do not need a Trigger once for an event that has button released. The release will only register for one frame. Trigger once would be appropriate for a button pressed condition if you only want the press to register for one frame rather than the duration the button is held down.
Edit: and it looks like you don’t necessarily need to use ToString anymore either, which is new to me! So this is totally fine too:
…unless you have variables with the same name e.g. one global and one scene with the same name. It’s much easier to just give them different names.
Thanks for the explanation, I’m completely new to this. Yes, I corrected the name error, changed var to just the name var and now the number 10, the assigned value of var, is displayed correctly on the screen. However, when I click on the logo, the value does not decrease by 1. What could be wrong?
Remove At beginning of scene
It means LITERALLY do this actions ONLY when game starts and never do it again (well unless you make another event with such action without At beginning of scene)
To you and @worriedpixels
I just tested and turns out if you have variables with same names as global and scene variables
NO MATTER which was created 1st
From the list it will display only scene vars
I have FakeVar1 and FakeVar3 both as scene and global vars
Where i agree with worriedpixels that this will work
I disagree that any1 should do it
Look if you have variable HP then that would mean it should be HP of single object not for any object
So for example for your player
So what is the point in having HP scene and global variable?
Or better example Score?
You want to check how much score player gain per level and how much totally
You do not have 2 variables named Score
You have scene variable called Score and global variable called TotalScore
Or even better create array in this case called Score
Yes! That was it. Everything works without “At the beginning…”. I was asking a ChatGPT before, so probably that’s why my results was out of date and they referred to the game as a whole, as if the variable test itself was the entire game. After I did the marking of the opponent on mouseover/touch, GPT suggested the end game text - which is quite funny.