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

Legacy GM Dynamically reading files

Phil Strahl

Member
So I have a directory with .png files and corresponding .json files. If I add them to my "included files" everything is peachy and accessing them with working_directory etc. works just fine. However, I would like to load and add them at runtime instead, because
  • I want to be able to change and pop new files in without having to re-compile the whole project again and update the binaries.
  • there are *a lot* of files and adding them manually in GM would take me ages.
I tried adding them manually to the directory with the game files and had a quick show_message loop displaying all files my game could find in this dir, but any files I had not added in GM into the "included files" bin don't show up.

Here's my problem in practice:

The files I added manually into my project to look like this:
Code:
+ Included Files
  + sprites
    + spr_test_1.png
    + spr_test_2.png
Upon loading my test-game, this code runs:
Code:
  var dir = working_directory + "sprites\";
  var file = file_find_first(dir+"*.*", 0)
  show_message(file); // debug output
  do
  {
  file = file_find_next();
  show_message(file);
  }until (!file)
The output is, not surprisingly:
Code:
spr_test_1.png
spr_test_2.png
BUT:
If I compile the game to a zip, then unzip it somewhere and copy a bunch of additional .png-files into the "sprites" directory, the output still remains
Code:
spr_test_1.png
spr_test_2.png
while it should be
Code:
spr_test_1.png
spr_test_2.png
spr_test_3.png
spr_test_4.png
... etc ...
I suspect this having to do with the fact of the game running in sand-boxed mode, and I wonder if there's a way around this without having the user each time give the game access to a folder via get_open_filename...

Hope I got my problem across and that any of you know a solution, if there's any.


UPDATE: Even stranger: I substituded working_directory with program_directory and it kinda worked ... in that if I changed the files to some other files with different filenames, those were found. Although never more than 2, the amount of files I have in the "Included Files" bin in GM:
 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
Remove working_directory, program_directory or anything like that. Just specify the relative file path to either a file located in the local storage or a file located in the game bundle and let the engine handle finding the correct path. Specifying an absolute file path other than one obtained from get_*_filename has a higher chance of screwing up the automatic path finding than making things work.
 

Yal

🐧 *penguin noises*
GMC Elder
I'm pretty sure there's an extension called GMFileSystem that removes sandboxing, so if you just plan to release your game on Windows it might be worth looking up.

I'm pretty sure that anything you put in the game's "save area" folder will always be found, so if you don't think going into LocalAppData to deposit files is too much work for hot-replacing them this should work... the tricky part is to figure out a good way to deploy the game using that approach since your players probably wouldn't like that extra step.

How much work is importing the files other than actually importing them? It's pretty easy to batch-import stuff as included files by just dropping it on GM, so if the quantity is the only problem it should be possible to speed up importing that way.
 
Top