|
|
|
|
Reply From: |
SingingApple |
This is pretty easy to do with the power of Godot.
Create a global.gd script an save it as an autoloaded singleton. (If you don’t know how to do it, click here. The link should lead you to the Godot Documentation with the necessary information).
Then you can create three variables in the global.gd script.
In the scene where you change the progress of each bar. You can set the current value of each progress bar to the three variables you created in global.gd script (This script can be accessed from anywhere within the game tree).
On reloading the scene you can set the three variables in global.gd script to the three progress bars. This will hopefully retain the value of the progress bars just as you wished.
Hope this helps.
Hi, thank you for your answer. I read the doc on the link you posted. I created a global.gd script and i added it in the Autoload tab of the Project settings. The script looks like this:
extends Node
var bar1
var bar2
var bar3
func _ready():
# Called every time the node is added to the scene.
# Initialization here
pass
I can’t manage though to get the second part work. In particular to read the value of the first bar again and then to set the value to the bar1 variable.
On the script attached to the button that switch to the first scene i tried something like this:
extends Button
#onready var bar1 = get_node("/root/global")
func _pressed():
get_tree().change_scene("res://Game.tscn")
bar1 = get_node("../TextureProgress1").get_value()
get_node("../TextureProgress1").set_value(bar1)
#global.bar1(value1)
func _ready():
# Called every time the node is added to the scene.
# Initialization here
pass
I really don’t know what am i doing wrong and i’m a bit stuck at the moment. Do you have any suggestion? Thank you
Your code looks suspicious to me.
Try something like this on the button that switches the scenes:
extends Button
var val_bar1
func _pressed():
val_bar1 = get_node("../TextureProgress1").get_value()
GLOBAL.bar1 = val_bar1 #I am asuming your script is stored as GLOBAL in the Autoload section
get_tree().change_scene("res://Game.tscn")
SingingApple | 2018-01-24 12:35
Hey, thank you for your answer.
Yes i have a global.gb script called global, flagged as singleton in Autoload tab of the Project Settings.
Anyway i got two buttons: one that switch to scene 2 and one to switch back to scene 1. The button in the second scene (that switch to scene 1) is the only thing present in the scene 2, while in the first scene there are every bars and buttons.
I tried your code just now and, the line that contains the code “GLOBAL.bar1 = val_bar1” it returns an error: “Unexpected indent”
Hello, do you have an example of how I would save a custom created character in a global.gd?
Amateur.game.dev. | 2021-01-14 14:08