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

GameMaker directory syntax help

GML:
#event other_game_start
if !directory_exists(working_directory + "\config\")
{
    directory_create(working_directory + "\config\");
}

#event step
if directory_exists(working_directory + "\config\")
{
    game_end();
}

#event other_game_end
if directory_exists(working_directory + "\config\")
{
    directory_destroy(working_directory + "\config\");
}
how do i get this 2 work? ive tried doubling up the \s but the game doesnt end, suggesting its not reading or writing the config correctly, if i use it as written it gives a compilation error saying "Invalid token \", if i dont include the second \ it doesnt end the game, if i include a space after the second \ it doesnt end

the documentation appears incorrect on https://docs.yoyogames.com/source/dadiospice/002_reference/file handling/directory_exists.html

wats the correct syntax here? im out of guesses
 

FoxyOfJungle

Kazan Games
Try:

GML:
if directory_exists(working_directory + "config/")
{
    game_end();
}
or:

GML:
if directory_exists(game_save_id + "config/")
{
    game_end();
}
According to my tests, using / also works perfectly.

Detail, in GMS 2 you need to use two \\ to work, in GMS 1.4 I don't remember if it was like that, but I don't think so.
 
Try:

GML:
if directory_exists(working_directory + "config/")
{
    game_end();
}
or:

GML:
if directory_exists(game_save_id + "config/")
{
    game_end();
}
same issue, bc the \ is canceling the " in the code, so its reading
GML:
config")
as the input instead of
GML:
config\
, and its not closing the parenthetical
 

TsukaYuriko

☄️
Forum Staff
Moderator
All file paths are relative. Relative to what depends on what you're doing and where a file with the path and name you're looking for exists (if any) and, if it exists in multiple valid locations, additionally depends on which location is prioritized. Don't concern yourself with this and leave finding the correct base path up to the engine.

Remove working_directory.
The cases in which it's needed (as opposed to useless or potentially harmful) are few and far in between, if they even still exist. The 1.x manual states that it is required for mobile platforms, and only for those. This statement has disappeared from the 2.3 manual.

Replace all backslashes with forward slashes.
Using backslashes over forward slashes brings absolutely no advantages, only the disadvantage of having to use two of them so you don't accidentally escape something. You can do some quite entertaining stuff with various kinds and combinations of slashes, though.

Remove the leading slash and trailing slash.
Again, useless at best and harmful at most.

(Edit: Clarity, sources.)
 
Last edited:
All file paths are relative. Relative to what depends on what you're doing and where a file with the path and name you're looking for exists (if any), and if it exists in multiple valid locations, additionally depends on which location is prioritized. Don't concern yourself with this and leave finding the correct base path up to the engine.

Remove working_directory.
Replace all backslashes with forward slashes.
Remove the leading slash and trailing slash.
im still failing 2 understand, this is wat i think ur telling me 2 do
GML:
#event other_game_start
if !directory_exists("config")
{
    directory_create("config");
}

#event step
if directory_exists("config")
{
    game_end();
}

#event other_game_end
if directory_exists("config")
{
    directory_destroy("config");
}
but it doesnt work, & ive tried using / in place of \, in all variations but none of them still work, is there some other issue?
 

TsukaYuriko

☄️
Forum Staff
Moderator
The previous post has been edited since you replied - you may want to recheck it in case there's anything relevant.

Anyway, yes, that's exactly what I meant.

What exactly does "doesn't work" mean?
What happens when you run the game?
Is the folder being created? (Disable all code that destroys it to verify.)
Where are you looking for the folder?
What is your full and exact GMS 2 version number?
What is your target platform?
 
GML:
game_end();
is not being run, folders r not being created relative 2 the installpath (idk if this is where its meant 2 b creating them, but its not)
 

TsukaYuriko

☄️
Forum Staff
Moderator
Yeah, nope. :p

Folders will be created in the path defined under Game Options -> Windows (if on Windows) -> General -> Options -> Save Location. That's either %LOCALAPPDATA%/<Game Name> or %APPDATA%/<Game Name>. If not on Windows, it will be created as defined on the File System page.
 
Yeah, nope. :p

Folders will be created in the path defined under Game Options -> Windows (if on Windows) -> General -> Options -> Save Location. That's either %LOCALAPPDATA%/<Game Name> or %APPDATA%/<Game Name>. If not on Windows, it will be created as defined on the File System page.
as far as i can see its not even creating a folder w the game name in %localappdata%, im assuming the <game name> is the project file name? also checking %appdata%
 

TsukaYuriko

☄️
Forum Staff
Moderator
im assuming the <game name> is the project file name?
That is correct.

Rather than checking both locations, check the one you defined in your game settings. There's no merit to checking the other one.


For reference, what is your full and exact GMS 2 version number? There may be differences between versions (in terms of features or bugs), so being aware of that can only be helpful.
 
That is correct.

Rather than checking both locations, check the one you defined in your game settings. There's no merit to checking the other one.


For reference, what is your full and exact GMS 2 version number? There may be differences between versions (in terms of features or bugs), so being aware of that can only be helpful.
IDE v2.2.5.481 Runtime v2.2.5.378
by checking i mean opening windows explorer & pasting %appdata% & %localappdata% in, not referencing it in code
either way no new folders r being generated by the executable, even when run as administrator, any solutions jump out @ ya given this info?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Do you have any firewall or antivirus software installed? It may be preventing the game from creating files/directories, so try disabling any such software temporarily to see if that's the culprit.

That aside, not using a one year old version might help... although I'm not aware of any breaking changes to this functionality having been introduced since a long time. Just to be sure, test this on the latest version (2.3.1.542 as of writing). I'm not necessarily proposing this as a solution, just to rule out potential version differences.
 
Do you have any firewall or antivirus software installed? It may be preventing the game from creating files/directories, so try disabling any such software temporarily to see if that's the culprit.

That aside, not using a one year old version might help... although I'm not aware of any breaking changes to this functionality having been introduced since a long time. Just to be sure, test this on the latest version (2.3.1.542 as of writing). I'm not necessarily proposing this as a solution, just to rule out potential version differences.
updated & all issues persist
ive been able 2 create folders in the pass via file_create, but directory_create is yielding no results, is it deprecated code? is there some other way of creating, destroying, & checking folders?
 

TsukaYuriko

☄️
Forum Staff
Moderator
You didn't mention anything about security software, so I'll have to ask again: Do you have any firewall or antivirus software installed? It may be preventing the game from creating files/directories, so try disabling any such software temporarily to see if that's the culprit.

directory_create is not deprecated and is what you should be using.

You can also try creating the game's save folder (the one in either of the appdatas) manually if the game fails to create it on its own. Maybe that'll help it get going. Of course this isn't the ideal solution, but it would be a step forward for the moment.
 
Top