0 votes

Hope you are doing well. I wonder if a script can change its variable permanently. I'll clarify my question with an example. I have a variable, let's say:

var time = 0

Can a function change var value permanently so that the next time it's something else but "0" even after I restart Godot?

For example, the next time I open the script I see:

var time = 378

Is there any way the script can rewrite the var value automatically and update itself?

Why do I need it you ask? I want to dump JSON.

in Engine by (307 points)

You mean after you restart the programm? or do you mean next time when you run your function again without restarting the programm?

I mean after I restart the program. Let me put it this way, I can manually change the value of a variable, right? But can I write a function to do it automatically? So that the initial var value is always the updated value?

var = 0

if blah-blah:
var = 57

And the next time I start Godot (or a level) the variable is 57

var = 57

if blah-blah:
var = 178

And so on.

1 Answer

0 votes

im sorry, no, you have to implement a save and load mechanic to do so.


by (3,122 points)

Thanks mate for the reply! I was hoping maybe there was a simpler way, but it seems like I have no choice but make friends with JSON :)

There is a simpler way, no JSON required:

Huge huge thanks mate!!! I'll check it as soon as I can. Please add it as an ANSWER so that I can select it as the BEST ANSWER for those in the same boat.

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.