I'll try to explain it to you simply. I hope you don't mind if it looks a bit like patronizing.
delta
is not a magic word that can be used anywhere. It's a variable that is given as a parameter to the _process
function. And it doesn't have to be delta
. It's the name you give to the parameter, and you can change it. Example:
func _process(aaa):
print("delta is now aaa and its value is ",aaa)
See? Now it's not delta
anymore but aaa
. And if you try to use delta
in my example, like:
func _process(aaa):
print("delta is now aaa and its value is ",aaa)
print("delta = ",delta)
You'll get an error because delta
is not known.
Second, since this is a parameter, it is only known in the function and not outside. We say that the scope of the parameter is within the function. And that's the same for any variable you declare in the function. Example:
func _process(delta):
var my_var1=5
# delta is known here, and my_var1 too, but not aaa nor my_var2
func _some_function(aaa):
var my_var2="hello"
# a is known here, and my_var2 too, but not delta nor my_var1
If you want to have a variable whose scope covers the whole file, you must create a field. Example:
var myfield1="hi"
func _fixed_process(delta):
print(myfield1) # this works
myfield="hello" # you can change it too
func some_function():
print(myfield1) # this works too
Now you can guess that what you seek is to set the delta
of the parameter to a field.
var mydelta=0
func _fixed_process(delta):
mydelta=delta
func some_function():
print(mydelta) # print the delta of the last fixed_process run
Of course, you can also pass the parameter to another function, like suggested by tiernich.