I have tried to make an update system for my game, and this is how far I got.
First, connect to my server, and download an .ini file containing the name of the newest version of the game:
http_get_file("http://mywebsite.com/game/Versions.ini", working_directory + "/Versions.ini");
The first part tells Gamemaker where to find the file online, and the last part tells it where to save it locally.
Now, you have to test if the file was actually downloaded:
if file_exists("Versions.ini") {
I’m not sure of this function is optimal for larger downloads, because I don’t know if the file exists before the download is complete, but for small downloads like this very small text file, I haven’t found any issues yet.
If it the file was downloaded, read the file:
ini_open("Versions.ini"); global.NewestVersion = ini_read_string("Versions","Newest","ERROR"); ini_close(); }
First the file is opened, then the string global.NewestVersion is set to the value that is in block “Versions” called “Newest”. And if that value doesn’t exist, set the string to ERROR. And then the file is closed.
By the way, the .ini file should look like this to work with the code:
[Versions] Newest=”1.0”
This one will say that the newest version is version 1.0
Anyway, as soon as you have the global.NewestVersion, you just have to compare it to a string in the game, that tells the game what version it currently is. I usually do that by creating an object without sprites, that makes a new string called global.CurrentVersion when the game starts.
If the strings match, do nothing.
If global.NewestVersion is equal to “ERROR”, inform the user that there was an error.
If none of these things are true, start downloading the new installer, and when it’s done, execute the installer, and close the game right after executing.
Now the installer can install the new game, and everybody’s happy.
Unfortunately, I couldn’t make the last part work, because when I used the same method for downloading the .exe as I used for downloading the .ini, the .exe ended up being “damaged”.
So I figured what the heck, and instead I made my game open a website, where it said “there is a new update”, and then you could click on a link to download the update. In that way, I let the browser deal with downloading the executable, and then everything works fine!
If anybody knows how I can download an executable without damaging it, I’m all ears.
Ps. If you want to have data about how the download is going, you can store the download progress in a string, like this:
STRING = http_get_file("http://mywebsite.com/game/Versions.ini", working_directory + "/Versions.ini");
Now you can use a function that looks something like this to get info about how far the download is, and If there were any errors:
ds_map_(async_load, “WHAT YOU WANT TO KNOW ABOUT”);
But unfortunately, this never worked for me either.
.gexfile written by the video author. (I haven't got Game Maker installed, so I can't really test it. Definitely post it as an answer if you get it to work!) \$\endgroup\$