• 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!

HTML5 Reading a File from Another Game's Working Directory in HTML5

Posho

Member
Hello,

I am working on an HTML5 game that uses an image export button. I have an extension that allows me to save the game's screen to an image in HTML5 but only works if WebGL if off, however my game overall does require the use of WebGL.

My first idea around this is to save the data that will be necessary for drawing the screenshot in a local INI file, then open a new tab that would load a completely different HTML5 game, load the INI file, draw the contents and finally prompt to save the image. The only issue here is that by the nature of how Working Directories work in GameMaker: Studio function, I am having trouble with reaching/reading the INI file in the second HTML5 game.

What could be a solution to this? My other idea would be to save the INI file in a web server and then reach it from the other game through an URL, though I feel that this would be a pretty lazy and inefficient way to solve this.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
The issue is that you cannot reliably get a screenshot of a WebGL game unless WebGL was initialized with specific arguments, but it isn't for GMS games, and that is not easy to change because it happens very deep in the engine code.
 

rwkay

GameMaker Staff
GameMaker Dev.
The issue is that you cannot reliably get a screenshot of a WebGL game unless WebGL was initialized with specific arguments, but it isn't for GMS games, and that is not easy to change because it happens very deep in the engine code.
Can you point us at how to do that Yellow... not aware that we had to do some magic behind the scenes to make that work.

Russell
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Can you point us at how to do that Yellow... not aware that we had to do some magic behind the scenes to make that work.

Russell
It's preserveDrawingBuffer. Last time I checked, it's value was set from a option in GGS-values object, but the name was obfuscated even in debug mode, which suggests that someone added it a long time ago and it was completely forgotten. I suppose that it would be best left as a toggleable option just in case there is any performance cost to it.
 

Posho

Member
The issue is that you cannot reliably get a screenshot of a WebGL game unless WebGL was initialized with specific arguments, but it isn't for GMS games, and that is not easy to change because it happens very deep in the engine code.
Actually the issue here is not the image saving part of the code, I already got that part figured out. I just need to figure out how to load files from other working directories.

I just looked at your signature spoiler and it looks you have made a working screenshot maker for HTML5. Does it work with WebGL toggled on? If so, this could be it and save me the whole "making a separate game project" nonsense.
 

Posho

Member
@YellowAfterlife I just tried using your extension and it does indeed require having the WebGL disabled. Do you think there's a way to make your function work using a surface instead of the game screen? Or is it still the same if WebGL is enabled?
 

FrostyCat

Redemption Seeker
The emulated file system in the HTML5 export doesn't support directly sharing "working directories". You have to replace your INI system with an extension that calls local storage functions, AND you have to serve both games off the same origin.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
@YellowAfterlife I just tried using your extension and it does indeed require having the WebGL disabled. Do you think there's a way to make your function work using a surface instead of the game screen? Or is it still the same if WebGL is enabled?
Try calling the function somewhere in a low-depth object's Draw Event (while it'd still be drawing into application_surface). If that doesn't do it, probably not without YYG adding an option for it.
 

Posho

Member
I found something that should work, but for some reason is not working for me.

So after fiddling a lot I found out that in HTML5, if you put an exported game to a server and save an INI file from the game, you'll be able to read the same INI file from another version of the same game project saved in a completely different directory within the server. You don't even have to alter thae path or working directory. So for example, https://game.com/index.html/ and https://game.com/folder/index.html/ can share and load/save the exact same INI file without altering the directories. I have no idea why it works but it does.

That being said, I've been experimenting so I can maybe use this in my advantage, but I've been getting errors for reasons I can't explain. I'm exporting the original version of the game in a directory, then saving a version with altered rooms and layouts in another directory and both can save/load the same INI file with no problems. But then I'll save another version that loads the same INI file but from another object --even using the same script as the other ones, though it's just ini_read()-- and it simply can not retrieve the file. It's pretty confusing, to be honest.

I really need to step up my web programming game, like, pretty badly. o_O

Try calling the function somewhere in a low-depth object's Draw Event (while it'd still be drawing into application_surface). If that doesn't do it, probably not without YYG adding an option for it.
Nah, doesn't work. It works perfectly fine with the WebGL turned off, though.

The emulated file system in the HTML5 export doesn't support directly sharing "working directories". You have to replace your INI system with an extension that calls local storage functions, AND you have to serve both games off the same origin.
This is exactly what I wanted to avoid, but I'm already at it. I'm using an Extension from the Marketplace that does PHP-based permissions for saving/loading INI files.
As of now I can save files to my server perfectly fine, but I'm having some issues with loading. Apparently because of some browser restrictions.
I'm already discussing it with the developer of the extension.
 
Top