Topic was automatically imported from the old Question2Answer platform.
Asked By
thecolorfive
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?
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)
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.