Var

BlitzMax Forums/BlitzMax Beginners Area/Var

Yue(Posted 2015) [#1]
Hello, for serving the keyword Var ?.


Derron(Posted 2015) [#2]
SuperStrict
Framework Brl.StandardIO

Function FunctionA:int()
	local valueB:int = 10
	FunctionB(valueB)
	print valueB


	local valueC:int = 10
	FunctionC(valueC)
	print valueC
End Function


Function FunctionB:int(variable:int var)
	variable = variable * 2
End Function

Function FunctionC:int(variable:int)
	variable = variable * 2
End Function


functionA()


For complex types this differs (they are passed "by reference" already).


bye
Ron


Brucey(Posted 2015) [#3]
Yep. Primitive variables types (Int, Float, etc) are usually passed by value (i.e. a copy of their value is passed into a function).

With "Var", you can pass the variable by its reference in memory, allowing you to change the value of the variable within another function.


Yue(Posted 2015) [#4]
Local n:Int = 100

Function C(n Var)

         n = 500

End Function 

c(n)
Print n


Thanks You.