Iwant to be able to run or not run code depending on which platform I am building for. Some code should only run for the HTML5 platform. How can I found out whether the platform being run is HTML5 inside my gamemaker events?
You can check what browser the game is currently being run in with the os_browser constant. If the game is not being run in a browser the constant will be browser_not_a_browser. So to check if it is being run in a browser simply do:
This is my first time uploading a game on itch, and I'm running into kind of a weird bug and looking for some insight! So, for some background, I created my game in Gamemaker Studio 2 and exported it as HTML5 as a zip file. Inside the zip file is just the classic index.html file, options.ini, favicon.ico, and a folder called html5game with all my assets (textures, sprites, sounds, etc.). I think this is what you normally get when you export as HTML, so everything should be good there.
When I run the game on itch, the start screen loads just fine and functionally works. When I press [Z] to advance from the start room to the game room, that's where I start running into issues. Here's some screenshots below:
In the black screen/headphones picture above, the player is now in the game room ("rm_game" in GMS2), but I've placed what I've been calling an "Interstitial" screen as the top layer in the GUI to see if you're a new player or returning player. This specific Interstitial screen gets shown for returning players, since there's a "Saved file found" in the option on the right. But this specific screen isn't supposed to show up unless a save file exists - which is weird because if this is the first time I'm running this game, there shouldn't be an existing save file. When I try the option on the right, it just loads into a black screen. When I start a new game with the left option, it goes back to the start room (which should happen) but when I advance with [Z] I just get this same exact screen, and am back at square one. Also, the game is extremely laggy at this point.
I'm thinking it might be a problem with the way i'm save/loading. I followed shaun spaulding's save/load method here (Save / Load tutorial) which I think is pretty standard, and called my save file "dive.save" and saved it in a global variable called save_file.
Here's the error I'm getting in the console when it hits the interstitial screen. There's a huge number of requests being made, and it seems like my browser is hitting up itch's CDN (where my game files are hosted) multiple times without success. I think a 403 is a permissions denied error.
please note that ALL HTML5 games on ItchIO share the same localStorage! You need to create very specific naming for your save file, or put your save files in a special folder to avoid accidentally reading other games save files
Hey FieryLion, thanks so much for the response! Tried both things you suggested and neither have worked for me yet. Tried naming my file something very specific, like "dive-bitsloth-129304878321094" and no success. I also tried creating a new directory called "Saves/" and using working_directory like you suggested - no luck there either. I may be coding it wrong, so will take another look, but is there anything else you know of I could try?
Hope all is well and thank you for the in-depth code. Apologies for the late response as I haven't gotten a chance to work on this till now. Your code was helpful, but I'm actually saving my game in a bit of different way. I write all the information into a data structure first, then push to array. Then using "json_stringify" I turn the array into a json string and save to a temporary buffer that includes my save file.
When loading files, it's the same process but backwards. Read from the buffer, then "json_parse", then pop values off the array and back into the objects. After working on this tonight, I feel like I've tried everything. With and without "working directory" and also using a save folder like:
I've tested this locally and other than some visual glitches, the saving works functionally. The screen that's coming up can only possibly appear if a save file exists, which I don't see how is possible if it's my first time running the game and have never saved before on itch's server. At this point I'm thinking there's something wrong with itch's CDN as my game saves perfectly on my local server and the 3rd set of characters is a randomly generated 50-character string. Not sure what else to do at this point.
which should only appear if a saved file was found. I've tried doing the "Start New Game" option which finds and deletes the current save file, but it doesn't really do anything and I still see this screen. Also, the 50-char randomly generated string for the save file variable was a pretty new addition, but after uploading that and running for the first time, same problem. There shouldn't be a duplicate of it on itch's server I believe.
However, I think I know what's going on! I was doing some research earlier tonight and starting looking into the actual errors themselves. 403 is a permissions error, which I think means my game isn't able to access the save file on the remote server. So what I believe is happening (just an educated guess) is that somehow, the game thinks a save file exists, but when it goes to grab it from itch's remote server, it doesn't actually exist so is producing the errors above. I checked GMS2's documentation for "file_exists" and found something really interesting: _Language/GML_Reference/File_Handling/File...
So I'm assuming that's the error, since the way I'm checking save files is using that function. However, I do know that you're also using that same function in your code and it's working, so I'm really not sure what's going on ?.
3a8082e126