0 votes

In this script there are some variables. I want that when they become true, they will remain true even when you close the game. How can i do that?

in Engine by (55 points)

1 Answer

0 votes

Create a save system.

You can't really make a script permanent, nor make a variable stay the same if you close the game, so you're gonna have to make a save system so then you can put your variables in a file and just read that file to then set the variable you wanted to that.

Here's a good tutorial on how to do this, incase you dont already know how:
tutorial by game endeavor

by (439 points)

I've watched it but he doesn't explain how to manipulate variables. How can I change their values with code? Like his variable "health" he changes it with an other software, but how can I do with gd code?

Here's another video that make a little bit more sense

better video

i didnt actually watch the previous video beforehand, sorry about that!
This video is the tutorial I followed to make my own save system in my own game, I hope it helps you with what you want to do!

if you have any questions, I'll be happy to help you

Ok, I copied that script, the only thing I don't undestand is what should I write as var path

if you want the file to be editable when you're play-testing the game, use "res://data.json". but if you want it hidden for the regular user, use "user://data.json".

the only difference is that "res://" path saves the json file in your project folder, and the "user://" path saves somewhere hidden (I dont particularly know where, but its definetly hidden from the user)

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 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 webmaster@godotengine.org with your username.