VAR

BlitzMax Forums/BlitzMax Beginners Area/VAR

Eric(Posted 2005) [#1]
What is the true purpose in this Command and how can it help me to write better code.


N(Posted 2005) [#2]
You can use it to pass variables by-reference (and return multiple values from functions).

Function Foobar( a Var, b Var, c Var )
    a = SomethingMeaningful
    b = SomethingAlsoMeaningful
    c = AYourMomJoke
End Function



Tom Darby(Posted 2005) [#3]
Here's another example (with a call to the function using the by-reverence variables):


Graphics 640, 480, 16, -1

Function GetMouseCoords(xToSet var, yToSet var)

	xToSet = MouseX()
	yToSet = MouseY()

End Function

Local myX, myY

	myX = 0
	myY = 0

	Print myX + ", " + myY
		' output will be "0, 0"

	MoveMouse(200, 400)

	GetMouseCoords(myX, myY)

	Print myX + ", " + myY
		' output will be "200, 400" because myX and myY were passed by reference




N(Posted 2005) [#4]
using the by-reverence variables


Haaaaaaaaaahahahahahahahaha. Oh, that was a good laugh...


Tom Darby(Posted 2005) [#5]
Heh.

Fery vunny.

(Now bown down to the variable!)


Azathoth(Posted 2005) [#6]
It can also be used to get the contents of a ptr to a variable. An example is given for the ptr keyword.


tonyg(Posted 2005) [#7]
...what can var ptr be used for?


Azathoth(Posted 2005) [#8]
varptr gets the pointer of a variable.


tonyg(Posted 2005) [#9]
Yep, but what can you do with that information?


Azathoth(Posted 2005) [#10]
I think some API functions need ptr to variable.