I want to check what is the value of the variable var from another scene.

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

I want to check what is the value of the variable var from another scene.
For example, I have a scene level1 and I want to make a check in it.
There is a variable var in another scene (is_dead = false)
When a character dies, the value of the variable changes on true.
How can I check this through the operator if?

I not cool in code. but there is mine

extends Node2D

onready var Gameoverstats_player = get_node(“/root/Player”)

func _process(_delta):
$Stats/CanvasLayer/Label.text = str($Player.coins)
#if $“/root/Player”.is_dead = true (the is the problem)
$Gameoverstats/CanvasLayer/Label.show()

Spaliasum | 2020-08-09 14:35

Don’t understand why you got $"/root/Player" and $Player but this should be enough:

if $"/root/Player".is_dead:
  $Gameoverstats/CanvasLayer/Label.show()

without = true, actually it should be == true with double = but since it’s a boolean you can omit it.

Dlean Jeans | 2020-08-09 16:24

:bust_in_silhouette: Reply From: maze_maze

This question has already been answered

https://forum.godotengine.org/36556/how-to-get-the-value-of-a-variable-from-another-scene

:bust_in_silhouette: Reply From: Codicattus

I think the best way is to use a global variable with Autoload
Singletons (Autoload) — Godot Engine (stable) documentation in English