SOLVED How to include files to the game at runtime ?

I'm not making a game exactly but a program (yeah I'm that guy who will use game maker for making programs huh). I'm making a simple tool to create UI for GMS2 in a similar way to Unity Cavnas/UI system with a standalone graphical interface. I want the user to be able to test the font he/she is using in his/her game while creating the UI. Normally, I have to create a font or use the font_add function with the included font file (".ttf" or maybe ".otf"). how can I include a font file at runtime ? Is it even possible ?
 
Last edited:
Right click on the the Included File section of your resources panel and click insert included file. The file will then be accessible from working_direction+"\\file_name.ttf" or whatever you have called it. You can store it in folders by creating Groups found in the Included File right click menu. Each group can be considered a folder and you will have to specify the folder name along with your file name in the above file path text.
 

kburkhart84

Firehammer Games
The manual says the font can be added at run-time using font_add(), but it has to be part of the "included files" bundle. It does however let you specify the file path, so I'm not fully sure if it has to be part of the bundle or not. A few versions ago, they allowed the file sandbox to be disabled, so maybe you would be able to load fonts from anywhere now if you disabled the sandbox. I'd say its a good idea for you to try it if nothing else.
 
Also note, the reason that fonts are added as "sprites" and thus can't be resized properly at run-time has to do with licensing requirements I have heard (entirely possible that this is not true though, so maybe do some digging on your own). If it is true, then adding fonts that require credit/money to use to the included files might open you up to potential legal trouble if you don't follow the licensing requirements of the original font creator.
 
Right click on the the Included File section of your resources panel and click insert included file. The file will then be accessible from working_direction+"\\file_name.ttf" or whatever you have called it. You can store it in folders by creating Groups found in the Included File right click menu. Each group can be considered a folder and you will have to specify the folder name along with your file name in the above file path text.
I want to be able to add files while running the game/application. This isn't actually what I am asking about but it gave me an idea. If files are located in working working_directory, Can I just copy new files there while running the game and they will be ready to use without using the editor at all ?
 
The manual says the font can be added at run-time using font_add(), but it has to be part of the "included files" bundle. It does however let you specify the file path, so I'm not fully sure if it has to be part of the bundle or not. A few versions ago, they allowed the file sandbox to be disabled, so maybe you would be able to load fonts from anywhere now if you disabled the sandbox. I'd say its a good idea for you to try it if nothing else.
I did try what you suggested and it didn't work. I have to "escape" some characters first (like "C:\\Windows\\Fonts\\arial.ttf" instead of "C:\Windows\Fonts\arial.ttf"). Anyway, it just throws this error
Rich (BB code):
Error! not allowing save with filename 'C:\Windows\Fonts\Arial.ttf'.FreeType :: unable to find font file C:\Windows\Fonts\Arial.ttf
I tried different locations and fonts but the same error. However, copying the working directory to clipboard and moving the files manually and reloading room (or font_add) did the trick. Surprise! How can I let the user select files and how can I copy those files using game maker ? I guess I will add a bunch of fonts and just create a tutorial on how to add another font if I created the application.
 

kburkhart84

Firehammer Games
I can't disable sandbox, at least not in GMS2. Those functions are window only as listed here in docs. I will use them for now anyway. I found out I can also copy the files to working directory manually. Thank you for the information :)
You are not using Windows then? If that's the case, I'm not sure how you will be able to get around the sandbox on other platforms since I understand that get_open_filename() is also specific to Windows builds only.
How can I let the user select files and how can I copy those files using game maker ?
The clipboard functions are also only on Windows...and copying/saving files won't help you in this case because of the same sandbox(unless you are doing it externally outside the actual game/project which seems to work). You may simply be out of luck on this one.
 
S

Sam (Deleted User)

Guest
I can't disable sandbox, at least not in GMS2. Those functions are window only as listed here in docs. I will use them for now anyway. I found out I can also copy the files to working directory manually. Thank you for the information :)
You may use get_open_filename and similar functions on Windows, Mac, and Linux via an extension like this one: https://forum.yoyogames.com/index.php?threads/dialog-module-for-windows-macos-and-ubuntu.44311/

Although there are still a couple bugs I found that are in dire need of fixing:

1) with synchronous dialogs, if you press a mouse button or a keyboard key to open a dialog, when the dialog closes you will need to clear the keyboard and mouse state because it won't do that on it's own, not sure why. This seems to work on Windows but on mac or linux you will need to press the previously pressed key twice before it will be usable again. :/

2) as for the async functions, if you use the same type of dialog more than once, it will treat the latter call as if it had the same arguments specified by the first call. This bug I found out just recently so there's a better chance of me getting this one fixed soon hopefully.

Sorry I don't have a better option at this time. It would help to know why you can't just disable the sandbox via game options. Or did you already try that?

Copying files can be done with my file manager extension bundled with dialog module. But you should be able to use file_copy without an extension by disabling the sandbox. Disabling the sandbox can be done on windows, mac, and linux, or with the appropriate extension, potentially any platform.
 
Last edited by a moderator:

kburkhart84

Firehammer Games
You may use get_open_filename and similar functions on Windows, Mac, and Linux via an extension like this one: https://forum.yoyogames.com/index.php?threads/dialog-module-for-windows-macos-and-ubuntu.44311/

Although there are still a couple bugs I found that are in dire need of fixing:

1) with synchronous dialogs, if you press a mouse button or a keyboard key to open a dialog, when the dialog closes you will need to clear the keyboard and mouse state because it won't do that on it's own, not sure why. This seems to work on Windows but on mac or linux you will need to press the previously pressed key twice before it will be usable again. :/

2) as for the async functions, if you use the same type of dialog more than once, it will treat the latter call as if it had the same arguments specified by the first call. This bug I found out just recently so there's a better chance of me getting this one fixed soon hopefully.

Sorry I don't have a better option at this time. It would help to know why you can't just disable the sandbox via game options. Or did you already try that?

Copying files can be done with my file manager extension bundled with dialog module. But you should be able to use file_copy without an extension by disabling the sandbox. Disabling the sandbox can be done on windows, mac, and linux, or with the appropriate extension, potentially any platform.
The catch with using extensions for get_open_filename() and even for getting around the sandbox is that it seems that font_add() simply enforces the sandbox on its own(going by the OP).
About disabling the sandbox...that doesn't seem to force font_add() to load fonts that aren't part of the included_files bundle regardless. Even the manual says that this is the case.
Copying files....if the sandbox does indeed get disabled, and somehow copying fonts to the working_directory makes them work with font_add() even if they weren't part of the original install, then that seems to be the best solution.
 
S

Sam (Deleted User)

Guest
Fortunately I found a fix to the async dialogs, so that does remain an option if they want to load a font from a selected file and have it copied to the working directory behind the scenes to enable loading the file.

The update will be published within a couple hours.

Edit:

Update published! :D
 
Last edited by a moderator:
You may use get_open_filename and similar functions on Windows, Mac, and Linux via an extension like this one: https://forum.yoyogames.com/index.php?threads/dialog-module-for-windows-macos-and-ubuntu.44311/

Although there are still a couple bugs I found that are in dire need of fixing:

1) with synchronous dialogs, if you press a mouse button or a keyboard key to open a dialog, when the dialog closes you will need to clear the keyboard and mouse state because it won't do that on it's own, not sure why. This seems to work on Windows but on mac or linux you will need to press the previously pressed key twice before it will be usable again. :/

2) as for the async functions, if you use the same type of dialog more than once, it will treat the latter call as if it had the same arguments specified by the first call. This bug I found out just recently so there's a better chance of me getting this one fixed soon hopefully.

Sorry I don't have a better option at this time. It would help to know why you can't just disable the sandbox via game options. Or did you already try that?

Copying files can be done with my file manager extension bundled with dialog module. But you should be able to use file_copy without an extension by disabling the sandbox. Disabling the sandbox can be done on windows, mac, and linux, or with the appropriate extension, potentially any platform.
This is really helpful. I tested it and it works as excepted on windows and I assume it will on mac/linux. Thanks mate <3
Here is how I did it :
GML:
file_copy_fmns(get_open_filename_fmns("Font Files|*.ttf", ""), working_directory + "custom_font.ttf")
custom_font = font_add("custom_font.ttf" , 48, false, false, 0, 255)
You said I can disable sandbox ? I can't find it anywhere main, window, mac, linux or even preferences. Can you provide a screenshot ?
 
S

Sam (Deleted User)

Guest
This is really helpful. I tested it and it works as excepted on windows and I assume it will on mac/linux. Thanks mate <3
Here is how I did it :
GML:
file_copy_fmns(get_open_filename_fmns("Font Files|*.ttf", ""), working_directory + "custom_font.ttf")
custom_font = font_add("custom_font.ttf" , 48, false, false, 0, 255)
You said I can disable sandbox ? I can't find it anywhere main, window, mac, linux or even preferences. Can you provide a screenshot ?
By the look of the _fmns suffix you are using a very outdated version of the extension which I thought was no longer available unless you happen to be using GMS 1.x? That would explain why you aren't seeing that in game options. I'll provide a screenshot, but I also recommend upgrading the extension to the latest version which may be downloaded from Google Drive on the marketplace page, because the 1.4 marketplace uploader is broken.
 
By the look of the _fmns suffix you are using a very outdated version of the extension which I thought was no longer available unless you happen to be using GMS 1.x? That would explain why you aren't seeing that in game options. I'll provide a screenshot, but I also recommend upgrading the extension to the latest version which may be downloaded from Google Drive on the marketplace page, because the 1.4 marketplace uploader is broken.
I'm using GMS 2 but marketplace showed the old gms 1.4 version. How could this happen ? Maybe because I'm using the browser or because I created this account when I was using GMS 1.4 ? I tried using the marketplace inside GMS2 and it just seems broken. I can search but I can't download. Old version works though.
 
Last edited:
S

Sam (Deleted User)

Guest
I'm using GMS 2 but marketplace showed the old gms 1.4 version. How could this happen ? Maybe because I'm using the browser or because I created this account when I was using GMS 1.4 ? I tried using the marketplace inside GMS2 and it just seems broken. I can search but I can't download. Old version works though.
Yeah you can just try downloading from here if the marketplace isn't working: https://drive.google.com/open?id=1nx62yTl3BUGXgCYhnFDjoMo3Yw5GGRPZ
 
Top