• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Android Checking Game Version for Android [SOLVED]

Hi dear GM community,

I have issue with Checking Game Version on Android.
On windows test works like charm, but after testing on android test its vice versa.
When new version bigger is, he goes directly in Room Menu, but he should go in Room Update.


GML:
    if web_version > "1.2.2" //the version number
        {
        room_goto(rmUpdate);
        }
    else
    if web_version <= "1.2.2"
        {
        room_goto(rmMenu);
        }
Maybe I miss something about android build?
 

chamaeleon

Member
What is the value of web_version when the first if statement is reached? I'm not asking what you think it is, I am asking what the program actually holds in the variable at that point in time (all characters would be important, including spaces, since you are performing a string compare). The debugger and show_debug_message() are crucial for finding out why certain things happen unexpectedly.

You don't need another test btw, if it's not greater, it must be less than or equal
GML:
if (web_version > "1.2.2") {
    room_goto(rmUpdate);
} else {
    room_goto(rmMenu);
}
or
GML:
room_goto(web_version > "1.2.2" ? rmUpdate : rmMenu);
 
Here is full code

GML:
async_ini = http_get("xxxxxxxxxxxx.ini");
GML:
//save ini/txt file from web to local directory
switch (evid)
    {
    case async_ini:
        result = ds_map_find_value(async_load, "result")
        file = file_text_open_write("xxx.ini");
        file_text_write_string(file, result);
        file_text_close(file);
        break;
    }
      
//Read ini 
ini_open("xxx.ini");
var web_version =  ini_read_string("version", "number", "");
ini_close();

  
//check for an update
if web_version > "1.2.2"
    {
    room_goto(rmUpdate);
    }
else
if web_version <= "1.2.2"
    {
    room_goto(rmMenu);
    }
in xxx.ini file is this section, key and default. Like this:
[version]
number="1.2.3"
 
Last edited:
What is the value of web_version when the first if statement is reached? I'm not asking what you think it is, I am asking what the program actually holds in the variable at that point in time (all characters would be important, including spaces, since you are performing a string compare). The debugger and show_debug_message() are crucial for finding out why certain things happen unexpectedly.

You don't need another test btw, if it's not greater, it must be less than or equal
GML:
if (web_version > "1.2.2") {
    room_goto(rmUpdate);
} else {
    room_goto(rmMenu);
}
or
GML:
room_goto(web_version > "1.2.2" ? rmUpdate : rmMenu);
anyway, your both of your codes works same, giving same result, but its better.
But issues is the same. It jus wont move to rmUpdate, he goes to rmMenu. 🤔
 

chamaeleon

Member
Its "1.2.3"
What's interesting when I change bigger > in Lesser < then he goes in rmUpdate.
Its like he is reading vice versa... :confused:
Did you get "1.2.3" from the android app running on your device by having it displayed and are they the only characters present in the string, or by looking at whatever resource that information comes from? If there's a space in front for example the comparison will not have the result you expect.
 

chamaeleon

Member
Create event
GML:
web_version = "1.2.3";
Draw event
GML:
draw_text(x, y, "Comparing version = " + string(web_version > "1.2.2"));
yields "Comparing version =1" on both Windows and Android for me.
 
Create event
GML:
web_version = "1.2.3";
Draw event
GML:
draw_text(x, y, "Comparing version = " + string(web_version > "1.2.2"));
yields "Comparing version =1" on both Windows and Android for me.
yea for me too, but web_version has to show that number from http link from xxx.ini.
And in ini.exe is this:
[version]
number="1.2.3"

you have full code on my second post.
 

chamaeleon

Member
Ini file
Code:
[version]
number = "1.2.3"
Create event
GML:
ini_open("version.ini");
web_version = ini_read_string("version", "number", "0.0.0");
ini_close();
Draw event
GML:
if (web_version > "1.2.2") {
    draw_text(x, y+64, web_version + " is greater than 1.2.2");
    show_debug_message(web_version + " is greater than 1.2.2");
} else {
    draw_text(x, y+64, web_version + " is less than or equal to 1.2.2");
    show_debug_message(web_version + " is less than or equal to 1.2.2");
}
Results in logging the following to the console output, and the corresponding drawn text in the Android app
Code:
10-14 19:34:33.706  4373  9868 I yoyo    : 1.2.3 is greater than 1.2.2
 
yea but that all manually and local.
When I wanna to read an INI from HTTP link, he does vice versa. I Think android cant read this:
[version]
number = "1.2.3"

maybe only 1.2.3

and i forgot to say this code is doing under Async HTTP event, only works with that event

GML:
//save ini/txt file from web to local directory
switch (evid)
    {
    case async_ini:
        result = ds_map_find_value(async_load, "result")
        file = file_text_open_write("xxx.ini");
        file_text_write_string(file, result);
        file_text_close(file);
        break;
    }
      
//Read ini
ini_open("xxx.ini");
var web_version =  ini_read_string("version", "number", "");
ini_close();

 
//check for an update
if web_version > "1.2.2"
    {
    room_goto(rmUpdate);
    }
else
if web_version <= "1.2.2"
    {
    room_goto(rmMenu);
    }
 

chamaeleon

Member
So.. We are back to the question from my first reply. What is the value? Not what you think it is, not what you want it to be. What it actually is, by having the program tell you.

Anyway.. What does your http request look like? My first guess is going to be that you are not using a https URL.
 

Mert

Member
Hi dear GM community,

I have issue with Checking Game Version on Android.
On windows test works like charm, but after testing on android test its vice versa.
When new version bigger is, he goes directly in Room Menu, but he should go in Room Update.


GML:
    if web_version > "1.2.2" //the version number
        {
        room_goto(rmUpdate);
        }
    else
    if web_version <= "1.2.2"
        {
        room_goto(rmMenu);
        }
Maybe I miss something about android build?
Wait.. nobody actually is telling the big issue here!!
Doing math operations on strings?

Normally, it would throw an error and crash the application but Game Maker Compiler just dismisses that.
Issue : You cannot do mathematical operations on strings. "12" and 12 are not the same things. Plus, there's no such thing as "1.2.2" in math. People usually enumerate the versions as 61 or 62.. to track the exact version of the app. What you should do is.

Create a #macro that holds the exact version value of your game. The value should be a number(real) not a string.

GML:
#macro gameVersionCheck 23
GML:
    if web_version > gameVersionCheck
        {
        room_goto(rmUpdate);
        }
    else
    if web_version <= gameVersionCheck
        {
        room_goto(rmMenu);
        }
Good luck
 
Okey guys, we lost ourselves right here now.
Again full code:

GML:
//Create Event
async_ini = http_get("Https:www.xxxxxxxxxxxx.ini"); // this link is only for example    with 1.2.3 version
GML:
//Async HTTP

switch (evid)
    {
    case async_ini:
        result = ds_map_find_value(async_load, "result")
        file = file_text_open_write("xxx.ini");
        file_text_write_string(file, result);
        file_text_close(file);
        break;
    }
    
//Read ini
ini_open("xxx.ini");
var web_version =  ini_read_string("version", "number", "");  //reads 1.2.3 
ini_close();


//check for an update
if web_version > "1.2.2"
    {
    room_goto(rmUpdate);
    }
else
if web_version <= "1.2.2"
    {
    room_goto(rmMenu);
    }
THIS code works perfectly on Windows, but not on Android.
Or android cant read that file or code cant access to that file.
Or android read this differently?
 
Last edited:
Wait.. nobody actually is telling the big issue here!!
Doing math operations on strings?

Normally, it would throw an error and crash the application but Game Maker Compiler just dismisses that.
Issue : You cannot do mathematical operations on strings. "12" and 12 are not the same things. Plus, there's no such thing as "1.2.2" in math. People usually enumerate the versions as 61 or 62.. to track the exact version of the app. What you should do is.

Create a #macro that holds the exact version value of your game. The value should be a number(real) not a string.

GML:
#macro gameVersionCheck 23
GML:
    if web_version > gameVersionCheck
        {
        room_goto(rmUpdate);
        }
    else
    if web_version <= gameVersionCheck
        {
        room_goto(rmMenu);
        }
Good luck
i will check that
 
Okey guys, we lost ourselves right here now.
Again full code:

GML:
//Create Event
async_ini = http_get("Https:www.xxxxxxxxxxxx.ini"); // this link is only for example    with 1.2.3 version
GML:
//Async HTTP

switch (evid)
    {
    case async_ini:
        result = ds_map_find_value(async_load, "result")
        file = file_text_open_write("xxx.ini");
        file_text_write_string(file, result);
        file_text_close(file);
        break;
    }
   
//Read ini
ini_open("xxx.ini");
var web_version =  ini_read_string("version", "number", "");  //reads 1.2.3
ini_close();


//check for an update
if web_version > "1.2.2"
    {
    room_goto(rmUpdate);
    }
else
if web_version <= "1.2.2"
    {
    room_goto(rmMenu);
    }
THIS code works perfectly on Windows, but not on Android.
Or android cant read that file or code cant access to that file.
Or android read this differently?
and if I do this manually, it works... but i need to read from ini file
GML:
if "1.2.3" > "1.2.2"
    {
    room_goto(rmUpdate);
    }
else
if "1.2.3" <= "1.2.2"
    {
    room_goto(rmMenu);
    }
 

chamaeleon

Member
If you are concerned with it being related to file reading and writing, why don't you use ini_open_from_string() instead, using the string you are supposedly getting back? Why would you assume the content of what your are storing is correct? Where is the verification of data? Oh, before I forget to ask, what is the value of web_version?

Personally, I'm not lost at all. I'm just asking posing questions that are not getting answers. Do you realize we could have been talking network issues yesterday if we could have put the issue of comparing strings behind us right away?

Anyway, I think I'm done in the thread. I'm not seeing any attempt to debug the value of any variable, be it web_version, result, success status of transmission, and so on, and I don't want to be used as the replacement for available debug tools.
 
If you are concerned with it being related to file reading and writing, why don't you use ini_open_from_string() instead, using the string you are supposedly getting back? Why would you assume the content of what your are storing is correct? Where is the verification of data? Oh, before I forget to ask, what is the value of web_version?

Personally, I'm not lost at all. I'm just asking posing questions that are not getting answers. Do you realize we could have been talking network issues yesterday if we could have put the issue of comparing strings behind us right away?

Anyway, I think I'm done in the thread. I'm not seeing any attempt to debug the value of any variable, be it web_version, result, success status of transmission, and so on, and I don't want to be used as the replacement for available debug tools.

To take and read something from link and store it needs to be done in Event Async HTTP, everything you said is just Create event ,Draw event and compare.
I tried to show debug_message from web_version in draw but from Event Async HTTP wont work. even debugger cant find web_version.

Anyway I will try that ini_open_from_string().

And Thank you for your time.
 

FrostyCat

Redemption Seeker
I am replying here because you are making "me too" necroposts on 5-year-old topics for this issue. Stop doing that. The guy from that other topic is not around anymore, and you have been around long enough to be expected to know that.

And where are people learning these kinds of sloppy HTTP habits from? Nowhere in your code are you checking the ID or the status. You are asking for chaos when things are anything but optimal. You also cannot compare version numbers in strings directly like that, if it happened to work it must have been a fluke.

Like I said in this topic, you should check both the ID and the status in the HTTP event:

Create:
GML:
async_ini = http_get("https://www.example.org/upgrades.ini");
HTTP:
GML:
if (async_load[? "id"] == async_ini) {
    switch (async_load[? "status"]) {
        case 1: break;
        case 0:
            ini_open_from_string(async_load[? "result"]);
            var web_version =  ini_read_string("version", "number", "");
            if (upgrade_required(web_version, GM_version)) {
                room_goto(rmUpdate);
            } else {
                room_goto(rmMenu);
            }
            ini_close();
            async_ini = -1;
        break;
        default:
            show_debug_message("Failed to reach update server, put off until later");
            async_ini = -1;
    }
}
upgrade_required:
GML:
///@func upgrade_required(newver, ver)
///@arg {string} newver
///@arg {string} ver
function upgrade_required(_newver, _ver) {
    var newver = _newver;
    var ver = _ver;
    var segments = min(string_count(".", newver), string_count(".", ver));
    repeat (segments) {
        var newver_pos = string_pos(".", newver);
        var newver_number = int64(string_copy(newver, 1, newver_pos-1));
        newver = string_delete(newver, 1, newver_pos);
        var ver_pos = string_pos(".", ver);
        var ver_number = int64(string_copy(ver, 1, ver_pos-1));
        ver = string_delete(ver, 1, ver_pos);
        if (newver_number > ver_number) return true;
    }
    return int64(newver) > int64(ver);
}
 
I am replying here because you are making "me too" necroposts on 5-year-old topics for this issue. Stop doing that. The guy from that other topic is not around anymore, and you have been around long enough to be expected to know that.

And where are people learning these kinds of sloppy HTTP habits from? Nowhere in your code are you checking the ID or the status. You are asking for chaos when things are anything but optimal. You also cannot compare version numbers in strings directly like that, if it happened to work it must have been a fluke.

Like I said in this topic, you should check both the ID and the status in the HTTP event:

Create:
GML:
async_ini = http_get("https://www.example.org/upgrades.ini");
HTTP:
GML:
if (async_load[? "id"] == async_ini) {
    switch (async_load[? "status"]) {
        case 1: break;
        case 0:
            ini_open_from_string(async_load[? "result"]);
            var web_version =  ini_read_string("version", "number", "");
            if (upgrade_required(web_version, GM_version)) {
                room_goto(rmUpdate);
            } else {
                room_goto(rmMenu);
            }
            ini_close();
            async_ini = -1;
        break;
        default:
            show_debug_message("Failed to reach update server, put off until later");
            async_ini = -1;
    }
}
upgrade_required:
GML:
///@func upgrade_required(newver, ver)
///@arg {string} newver
///@arg {string} ver
function upgrade_required(_newver, _ver) {
    var newver = _newver;
    var ver = _ver;
    var segments = min(string_count(".", newver), string_count(".", ver));
    repeat (segments) {
        var newver_pos = string_pos(".", newver);
        var newver_number = int64(string_copy(newver, 1, newver_pos-1));
        newver = string_delete(newver, 1, newver_pos);
        var ver_pos = string_pos(".", ver);
        var ver_number = int64(string_copy(ver, 1, ver_pos-1));
        ver = string_delete(ver, 1, ver_pos);
        if (newver_number > ver_number) return true;
    }
    return int64(newver) > int64(ver);
}
thank you for the answer. Yea I didn't watch good. And its not only for me, its good sometimes to re-post some stuff for beginners.
Anyway I appreciate your answer. I give you feedback little later.
 

FrostyCat

Redemption Seeker
It is probably because your INI file is not properly formed, and ini_read_string("version", "number", "") is returning the default empty string. Print out or debug async_load[? "result"] at that point to see what is in it.
 
So i tried your code almost works. On pc works great same as mine code but on android is little better but still issue.
What happens is that upon checking game version, game stucks in black screen. debug shows nothing, but here is some errors.



568 I yoyo : HttpGet("http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/GameVersion.ini", 4)
12-17 12:09:29.293 25538 25604 I yoyo : Received responseCode 301
12-17 12:09:29.294 25538 25604 I yoyo : http_get responseCode=301, id=4, finalurl=null headers=nokey: HTTP/1.1 301 Moved Permanently

12-17 12:09:29.294 25538 25604 I yoyo : Age: 0

12-17 12:09:29.294 25538 25604 I yoyo : Connection: keep-alive

12-17 12:09:29.294 25538 25604 I yoyo : Content-Length: 280

12-17 12:09:29.294 25538 25604 I yoyo : Content-Type: text/html; charset=iso-8859-1

12-17 12:09:29.294 25538 25604 I yoyo : Date: Fri, 17 Dec 2021 11:09:29 GMT

12-17 12:09:29.294 25538 25604 I yoyo : Location: https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/GameVersion.ini

12-17 12:09:29.294 25538 25604 I yoyo : Server: Apache

12-17 12:09:29.294 25538 25604 I yoyo : Via: 1.1 varnish (Varnish/7.0)

12-17 12:09:29.294 25538 25604 I yoyo : X-Android-Received-Millis: 1639739369293

12-17 12:09:29.294 25538 25604 I yoyo : X-Android-Response-Source: NETWORK 301

12-17 12:09:29.294 25538 25604 I yoyo : X-Android-Selected-Protocol: http/1.1

12-17 12:09:29.294 25538 25604 I yoyo : X-Android-Sent-Millis: 1639739369254

12-17 12:09:29.294 25538 25604 I yoyo : X-Varnish: 235080103

12-17 12:09:29.309 25538 25568 I yoyo : Failed to reach update server, put off until later
12-17 12:09:29.309 25538 25568 I yoyo : --------------
 

FrostyCat

Redemption Seeker
Your request failed in the first place, look at the Failed to reach update server, put off until later message at the end. Double-check your URL, and make sure that the URL starts with https://. Android does not permit plaintext HTTP by default.
 
Top