Functions

BlitzMax Forums/BlitzMax Beginners Area/Functions

po(Posted 2006) [#1]
Ugh. I use functions when I can, but I could be using them a lot more. I would save a lot of code if I could use them like this without having to make them global:
Local x:Int=10

ChangeX(x)

Print x

Function ChangeX(x:int)

x=5

End Function


Is there a way that I can use functions like this without making any Global variables?


Gabriel(Posted 2006) [#2]
Yes.

Local x:Int=10

ChangeX(x)

Print x

Function ChangeX(x:int var)

x=5

End Function


Adding var to the variable type in the function prototype ( as I've done in the code above ) passes it by reference instead of by value.


po(Posted 2006) [#3]
Why did I not know of this??
Thanks!


Dreamora(Posted 2006) [#4]
Because you didn't read the help files on the language carefully enough :)


po(Posted 2006) [#5]
Yes, that would've helped me sooo much :)