0 votes

What I want is to run a function the very first time the user starts the game.

I want to create a folder structure in user:// I can use later when I save the game and I figured out how to but I dont want to do that every time the game starts. What is the cleanest solution to run a function only the very first time?

in Engine by (378 points)

2 Answers

+2 votes
Best answer

ok! I don't know exactly how but it can help

func _ready():
    var file = File.new()
    if file.file_exists("user://###"):
        pass
    else:
        #create your file or folder here
by (942 points)
selected by
+1 vote

Directory.dir_exists ( *String* path ) -> *bool*

Returns whether the target directory exists. The argument can be relative to the current directory, or an absolute path.

You can use this function to check whether the folder structure has already been created.

by (90 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.