Functions

BlitzMax Forums/BlitzMax Beginners Area/Functions

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?

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.

Why did I not know of this??
Thanks!

Because you didn't read the help files on the language carefully enough :)

Yes, that would've helped me sooo much :)