How to make a script permanent

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MightyRat

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?

:bust_in_silhouette: Reply From: dustin

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

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?

MightyRat | 2020-06-19 12:12

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

dustin | 2020-06-19 12:36

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

MightyRat | 2020-06-19 14:02

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)

dustin | 2020-06-20 06:51