I have some more findings around this, that I'd gladly share here. When discussing this on Discord, @MikeDX pointed out to me that Fuze doesn't really pay attention to the type of variable. So in stead of using a specific type like int, I would recommend using var in stead. It's not an official keyword in Fuze, but it's a common keyword in other languages where a variable is declared with a keyword, without declaring the type with it (for instance, it occurs in C# and in JavaScript)
A = 1
B = 2
var n // pulls scope of n out of fn, it still needs to be assigned, but this can be done in fn now.
function fn()
var C = A // A still refers to global scope A, since it has not been declared in fn yet.
A = 3 // Updates global A to 3
var A = 4 // declares local A and assigns it 4 without touching global A
var B = 5 // same for B
n = "\n" // only because n has been used outside of fn, this assigns "\n" to the global variable n.
print("in:", n, A, n, B, n, C, n) // in \n 4 \n 5 \n 1
return void
fn()
print("out", n, A, n, B) // out \n 3 2
loop update() repeat
So in summary, this is how I'd suggest working this it:
Always declare your variables, for the scope they are used in even if you don't assign them a value yet
You can use var as if it where a keyword to declare your variable (I think that looks good and I thought that epiphany was worth a double post)
In some cases, you might want to assign a global variable to local variable before using them, but it's better to avoid ghosting your variables by using the same name locally in your function.