The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I've seen pop-up type tutorials for how an app works, in various windows and android apps, that is only shown the first time an app runs. I mean the type of thing that frequently has a "don't show this again" check box option, but not always. What would it take to get such a thing working? Also, would something like this cause the app to require storage access that the app would otherwise not?

in Engine by (18 points)

2 Answers

+2 votes

Hello,

I would save a value in a config file and check if that value has been set. You can use the Config file object to do this.
Here's some quick code that will do that. There's no error checking, but it does what it needs to do. The config file is saved (in Window) in C:\Users\USERNAME\AppData\Roaming\Godot\app_userdata\GODOT PROJECT NAME

extends Node2D

var only_show_once = false
var config_file = "user://settings.cfg"

func _ready():
    var directory = Directory.new();
    if !directory.file_exists(config_file):
        print("Config file doesn't exist")
    else:
        load_config(config_file)

    if only_show_once:
        print("This isn't the first time this app has been run")
    else:
        print("First run. Add some code to show a popup box.")
        only_show_once = true
        save_config(config_file)

func load_config(filename):
    var config = ConfigFile.new()
    config.load(filename)
    only_show_once = config.get_value("config", "only_show_once")

func save_config(filename):
    var config = ConfigFile.new()
    config.set_value("config", "only_show_once", only_show_once)
    config.save(filename)

The above code creates a text file that looks like this:

[config]

only_show_once=true

You can edit that with a text file and set the value back to false to check it works as expected.
You can also save other config values to that file.

by (2,035 points)
0 votes

You should be able to use the user:// directory to save and load files.
For example, using ConfigFile:

# on startup
var config = ConfigFile.new()
var err = config.load("user://settings.cfg")
if err == OK:
    var show_popup = config.get_value("startup", "show_popup", true)
    # show the popup if `show_popup` is true
    config.save("user://settings.cfg")
else:
    # couldn't load config file, show the popup
    pass

# when `don't show again` is pressed:
config.set_value("startup", "show_popup", false)
by (40 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.