I'm not sure what the difference is between before and after. But it's my understanding that Var lets you refer/ pass a specific variable to a function rather than copy it's value to another.
So with normal function parameters, you would pass some values to the function and it would then create new variables to put those values in. Those new variables would then be available inside the function as local. Modifying them wouldn't modify the original variables, since the data is a copy.
If you use Var when specifying the parameters of the function, you're defining that these parameters should a `reference to` real variables that you want to use. It creates a pointer to that variable. So instead of copying the value of the variable into anther local one inside the function, it actually lets you modify the original variable itself. The temporary local variable name is just an `alias` for that real variable. So changing the value of that local variable actually changes the content of the real original variable outside the function.
It's kind of like a per-variable way of making a variable temporarily Global for the purposes of using in a specific function, while not being Global to anywhere else unless also defined as such.
Function myfunct(b:Int Var)
b:+1
End Function
Local a:Int=2
myfunct(a)
Print a
should print 3. The `b` variable, local to the function, isn't so much a NEW variable as it is a reference to the actual `a` variable. Manipulating the b variable actually manipulates the a variable, as if they are one variable. So the b variable, used with `Var`, is sort of a pointer - in this case an int pointer to `a`. The only thing is, to the programmer, you don't use it as an int pointer (cus that would mean you'd have to add [0] on the end of it to change the value - blitzmax does that part for you).
So in the second example you gave, notice that p is an int ptr. They are using Var to refer to, I guess, printing the content of the variable that p points to. In this case it points to the c[] array. So printing Var p actually prints c[0], and then c[1] and so on.
I guess you are allowed to put the Var before or after the pointer name.
So with normal function parameters, you would pass some values to the function and it would then create new variables to put those values in. Those new variables would then be available inside the function as local. Modifying them wouldn't modify the original variables, since the data is a copy.
If you use Var when specifying the parameters of the function, you're defining that these parameters should a `reference to` real variables that you want to use. It creates a pointer to that variable. So instead of copying the value of the variable into anther local one inside the function, it actually lets you modify the original variable itself. The temporary local variable name is just an `alias` for that real variable. So changing the value of that local variable actually changes the content of the real original variable outside the function.
It's kind of like a per-variable way of making a variable temporarily Global for the purposes of using in a specific function, while not being Global to anywhere else unless also defined as such.
Function myfunct(b:Int Var)
b:+1
End Function
Local a:Int=2
myfunct(a)
Print a
should print 3. The `b` variable, local to the function, isn't so much a NEW variable as it is a reference to the actual `a` variable. Manipulating the b variable actually manipulates the a variable, as if they are one variable. So the b variable, used with `Var`, is sort of a pointer - in this case an int pointer to `a`. The only thing is, to the programmer, you don't use it as an int pointer (cus that would mean you'd have to add [0] on the end of it to change the value - blitzmax does that part for you).
So in the second example you gave, notice that p is an int ptr. They are using Var to refer to, I guess, printing the content of the variable that p points to. In this case it points to the c[] array. So printing Var p actually prints c[0], and then c[1] and so on.
I guess you are allowed to put the Var before or after the pointer name.