You know that thing with game stalling for a bit the first time you try to do something about a file, even if it doesn't exist in included files and is totally being created by your game? That's because the runtime checks the server if the file isn't in sandbox yet, and does so synchronously (meaning that the game freezes while awaiting response).

Since in some situations you do not want to check for file' existence on server before creating it in sandbox, I made this simple extension. It spots exactly one function - file_ensure(path, content). You can use it like so:

  • file_ensure("save.txt")
    Makes an empty file if it doesn't exist yet, preventing server polling.
  • file_ensure("save.ini", "[Some]")
    Makes a file with specified content if it doesn't exist yet.
    This is needed for INI files (have any section) due to specifics of implementation.
  • if (file_ensure("save.txt")) { /* write something to save.txt here */ }
    Create an empty file and perform custom code for filling it up if it doesn't exist yet.

As you can guess, you'd usually call file_ensure prior to starting to work with a file.
This happens incredibly quickly (<0.3ms) and thus can be used without fear.

The extension is made for JavaScript-based targets, but has fallback code for the rest as well (acting like file_exists+file_text_*).

Have fun!

StatusReleased
CategoryAssets
Rating
Rated 5.0 out of 5 stars
(1 total ratings)
AuthorYellowAfterlife
Made withGameMaker
TagsGameMaker

Download

Download NowName your own price

Click download now to get access to the following files:

file_ensure.gmez 1.4 kB
file_ensure.gmz 16 kB

Comments

Log in with itch.io to leave a comment.

This is a great extension to speed up load time of HTML5 games, but I wonder if there's a tweak to avoid it crashing on Chrome Incognito mode due to security restrictions? It happens only when the game is embedded (can reproduce it in this example).

(+1)

The easiest would be to wrap the function’s implementation in try-catch - incognito mode can be variously cursed, from localStorage existing but doing nothing (write something, read it back, and get nothing) to exceptions being thrown when trying to access it

Thank you very much!  Sounds good and that's what I'm going to do.

Is this for HTML5 Platform?? I'm looking to save GM HTML5 Program to Server... With the ability to save and load program "game".

This extension solves a specific problem, it is not necessary to save/load data on HTML5 “in general”.