Global variables don't work on Android

I noticed this in three different cases:

  1. With scene timer.

“if the timer is above 5 and the global variable test is equal to 1, the actions don’t happen”, it doesn’t matter the order of events.

  1. Checking two (or more) global variables at the same time:

In my case, it doesn’t work if I check the variable language and difficulty at the same time to translate the text from easy, average and hard to other languages.

  1. Getting the text from the global variable:

It doesn’t work at any time, when starting the scene, the text of the variable “mission” is changed but the text on the screen only gets the value it was before (If using an external event).

“Remembering that all these functions work normally within Gdevelop.”

Just because you encountered issues doesn’t mean that the feature doesn’t work. More likely, you were unable to make it work.
But since you’re not providing any relevant info or screenshots regarding the actual issue, we cannot offer any help aside from “try again”.

well. i use the cordova by Cmd to build the game for android. Besides it, I’m using JDK 8 (I’ve used 11, 14 and 15 as well) and Gradle 6.1, everything is running normally, except for the fact that gradle always says that the project has obsolete resources.

If necessary, when I turn the PC back on I will send a screenshot with examples of the 3 cases I mentioned. I think it might have something to do with Cordova as well.

I did in the events what I described in the post, so that’s basically it, it doesn’t work on Android and I don’t know if it’s a problem with the cordova or with the Gdevelop configuration for Android.

You need to initialize timers with the start/reset action. What you’re showing here shouldn’t work in preview either…

In the original events the timer starts with the scene, this is just a summary I made in another project. as I said before, everything works fine in the editor, but not after being exported.

Can you screen shot the actual code, in particular the sections that set the values of the global variables?

Here are the events of my project (which is in Portuguese), in the first one we can see that when the timer ends, if the difficulty is easy it will start another timer, if it is medium too and so on.
(I disabled it because it wasn’t working)

Here are some translations I manually put into the game, when changing the difficulty the translation of “easy, medium and hard” will change to the selected language.

And here is the quest variable that I use in an external event, whenever possible the text on the screen will change to the current quest.
(It only works after changing the scene and then returning to the same scene)

You haven’t provided a screenshot of where you set the global variables.

The reason I asked for this was to check where you are getting the values from. Is it from another scene, the same scene, a file somewhere else?

Oh sorry. The “mission” global variable is changed at the beginning of the scene (if there is a mission) so the text on the screen is changed to the variable’s text (using an external event) but this only works on Windows.

In languages, global variable is changed in the options scene, where it has the difficulty and available languages, as soon as a language is chosen the global variable changes along with it. The problem is just to check two variables at the same time because in the Editor it works normally, in Android it is only after changing the language several times that the translation of “easy, average and hard” changes.

How is it changed?

I’ve asked for a screen shot of the events so we can see how you are setting the global variable. Telling us what’s happening is not good enough, as you may be overlooking something that’s causing the issue. It happens to all of us, where we have code we swear should work. And it takes a second pair of eyes to identify it. You think it’s being set, but there may be a snip of flawed logic that’s preventing it from being set (this, by the way, is mere speculation, but we won’t know for sure until we see how you do it.) For example, if you do it by reading from a file, then that won’t work on devices.

1 Like

I’m not convinced at all that these wiggly accents are supported by the engine.
Using them in text/strings is one thing. Using them in variable names or anywhere else is asking for trouble, IMO.
One more thing that your useless ‘summary’ didn’t show us. If we ask for screenshots, it’s to help you, not to steal your game…

I will explain one more time. I’m using everything correctly.

If it wasn’t correct, it wouldn’t work on Gdevelop or Android. The ONLY FAULT is in Android to compare values/or texts of a global variable along with anything else.
If I just check “a variable” without using a sub-event it works.

And I’m saving the game in proper Android storage and I’m doing the JSON conversion from the scene variable to the Global as it’s recommended to do.

I didn’t want to send anything “useless”. I just thought I was sending you what you wanted to see. If it’s still necessary I’ll send a picture of the variables or compile the apk for you to understand what I’m trying to say.

In the scene that is mission 1, at the beginning the text of the “Mission” variable is changed, then in the sub-event it gets this text and shows it on the screen.
(works fine in Gdevelop)

Variables conversion and storage is working on both Windows and Android, on Windows I am using “FileSystem” to read and save the data and on Android I am using “Storage”

As soon as the game starts it reads and stores the data in the scene variable and then converts it to the Global variable. (working normally on both)

I just need to make sure it’s not an issue with the JDK (I use Jdk 8) or Cordova (latest version) as apparently it’s an issue that is only happening in the apk.
(If a screenshot is still needed the next time I start the program I will send it)

You are using 2 different systems. You cannot say it works on PC and not Android when one uses filesystem and the other uses storage. You are not comparing 2 the same things.

How have you confirmed it’s working on Android, and that it’s reading in the value?

I suggest you use storage on PC, make sure it works with that, then compile the same game for Android (without making any changes) and check if it still fails.

I created a new project using the same events I used in my game to test them all in one scene and apparently it worked correctly, both for checking the variables and changing the texts on the screen.

Which makes me wonder if it’s because I changed the Gradle version to 7.1.1 or if it’s because my game was built on an older version of Gdevelop.

(Here is a screenshot of the project I made working on Android)



It works on Android because as soon as I save the data (language for example) when I open the game again the language and level data remain the same as the last time. As soon as the game starts it checks whether or not it’s a phone so that’s why it checks the data on both platforms.

I’m using two different stores just for testing, at the moment I intend to make the game focused only on Android, in the case of Windows I use the File System so that I can delete data more easily.

(And I’m sorry if I’m not speaking English correctly because I don’t understand a lot and I use a translator.)

I’ve now tested with multiple save examples, switching them over to Global Variables, and in all cases they work fine on my device when using network preview, as well as when manually built.

I can’t give any guidance other than it is likely something specific to your project, whether that be using an old version of GD5, something with how you’re building, or your events aren’t the same as much as you think they are.

If other example projects work, or a new from scratch project works, it is unlikely to be a GD5 version or build process issue, but I can’t provide much other guidance since I can’t reproduce the issue.

when i opened the topic i was still having these problems, but then i made several changes that are not tested yet, like updating gradle, cordova and gdevelop. so as soon as i export the game with these changes i will update here too. If it goes well I will give the case as solved too.

Yes, definitely. I’m very interested in what you find out.