how can I to pass a paramter by reference?

Monkey Forums/Monkey Programming/how can I to pass a paramter by reference?

ziggy(Posted 2012) [#1]
That's the questio, how does one pass a paramter by reference, on a function declaration?


Samah(Posted 2012) [#2]
You can fudge it by passing in an array and modifying the contents.
Function Main:Int()
	Local arr:Int[1]
	Test(arr)
	Print arr[0]
	Return 0
End

Function Test:Void(someParam:Int[])
	someParam[0] = 5
End



ziggy(Posted 2012) [#3]
well, my scenario is, I'm writing a default general purpose function that gets a string representation of an HEX number, and returns the interget value of the number AND a bool that determines wether it the conversion was properly done or not. So I can't really use an array as they're different types and using an object just to be able to make a funciton call seems a bit overkill, dunno... Isn't there any var or byref or * or anything to pass a variable by reference?


AdamRedwoods(Posted 2012) [#4]

Isn't there any var or byref or * or anything to pass a variable by reference?


No.

Use an object, or use Poke() and Peek() in the new Data Buffer module. An object would be faster.

Or use an IntBox, as explained in the docs. edit: huh, intboxes don't allow to be mutable...