I have these script-wide variables named rng and number. What I want to do is make the number change every 10 seconds without making them local. How do I accomplish this?
var rng = RandomNumberGenerator.new()
var number = rng.randi_range(0, 100)
Oh yeah, I totally misunderstood. “script-wide” isn’t a thing. Though it’s a valid description.
What you are talking about is Scope. In this case, you have a class-scoped variable and are calling it “script-wide”. A “local” variable is one that is local to its scope and does not exist outside it. So a class-scoped (“script-wide”) variable is local to the class, or entire script.
Scope is determined based on where the variable is declared.
No, that’s different. Private variables are prepended with an underscore by convention in GDScript, but there’s no such thing as access modifiers (public, private, protected) in GDScript. Everything is technically public all the time.
Making a variable inside a loop is scope, not access modifier. It’s not private, it just gets deleted once the loop is done, and therefore doesn’t exist outside it.
Again, you’re describing scope, not access modifiers.