Declare Variable with values

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

Hello,
i have the following code:

var t = 1

func _ready():
	var t = 2
	return t

func _physics_process(delta):
	print(t)

In the console it prints 1, but i set t = 2, when the programme is started. Why is t =1 and how can i set it 2?
Thanks

:bust_in_silhouette: Reply From: estebanmolca

Redefinition of the variable t, in the function ready use t = 2 to invoke the global variable t. With var t = 2 within ready, you are defining another variable only valid within the ready function. Note that the word return leaves the function and will not execute any instructions below. return t is irrelevant here.