Question with boxing or passing references

Monkey Forums/Monkey Programming/Question with boxing or passing references

AdamRedwoods(Posted 2011) [#1]
I forget if there's a way to do this properly in monkey, or if it cannot:

Function Main:Int()
	
	Local mydata1:Int = 5
	Local mydata2:Int = 6
	
	Doit([mydata1, mydata2])
	
	Print mydata1
	Print mydata2
End Function

Function Doit( arbitrary:Int[] )
	
	arbitrary[0] = 7
	
End


My intention is a game load state, with many variables that need to be loaded. Trying to avoid a long list of:
varname = LoadSlotData(1)
varname = LoadSlotData(2)
varname = LoadSlotData(3) .. (50)
..etc...

My guess is that since you can't do it in Java, you can't do it.


Samah(Posted 2011) [#2]
That would require pointers. This is about all you could do for reading:
Function Main:Int()
  Local params:Int[] = New Int[2]
  Doit(params)
  Local mydata1:Int = params[0]
  Local mydata2:Int = params[1]
End

Function Doit:Void(params:Int[])
  For Local i:Int = 0 Until params.Length
    ' read into params[i]
  Next
End



AdamRedwoods(Posted 2011) [#3]
Ok, thanks, wanted to make sure there wasn't something I was overlooking.


Gerry Quinn(Posted 2011) [#4]
"My intention is a game load state, with many variables that need to be loaded. Trying to avoid a long list of:
varname = LoadSlotData(1)
varname = LoadSlotData(2)
varname = LoadSlotData(3) .. (50)"

Is that so bad, anyway? At least it's maintainable.


AdamRedwoods(Posted 2011) [#5]
I noticed there wasnt a "save game" module in the code archives, so was just trying to figure out a possible module that could take generic variables from a passed array. Not possible with monkey, thats ok.

I have a save game module written, pretty basic that uses the save state function, but requires the assignments when loading. Just isnt as clean as I'd been aiming for.