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!

More information

Published 32 days ago
StatusReleased
CategoryAssets
AuthorYellowAfterlife
TagsGameMaker

Download

Download NowName your own price

Click download now to get access to the following files:

file_ensure.gmez 1 kB
file_ensure.gmz 16 kB

Leave a comment

Log in with your itch.io account to leave a comment.