multi-dimension arrays ?

Monkey Forums/Monkey Beginners/multi-dimension arrays ?

Boulderdash(Posted 2016) [#1]
Im translating one of my old programs from blitz-max to monkey-x it was a "walk in the park", until I get to arrays ? I find myself reaching for another "work around" !

I dont like "work arounds" :-(

I dont understand how a high level language doesnt have multidimensional arrays ? Does this make the language better

A=Sprite[n , x, y]

Has to be replaced with.....

A=Sprite(n, x, y)
Field ArraySprite(100*100*100)
Method Sprite:int(n:int,x:int,y:int)
Return ArraySprite(n+(x*100)+(y*(100*100)) )
End

Or something.....

Is there a module solution please ?

I have realised this is going to bug me LOL

Im wondering if I should write a pre-processor to put in the array handling.

How do I program without multidimension arrays ? And why do I want to not use multidimension arrays ?


Gerry Quinn(Posted 2016) [#2]
It's not unusual - Java is the same. I think Monkey 2 is going to have real arrays

Here's what I use to easily allocate Monkey arrays:




If efficiency is your bag, you might also sometimes want to use 1-D arrays to 'fake' higher-dimensional arrays. (Effectively this would give you C-style arrays. Unfortunately Monkey doesn't have inline methods/functions or macros, which would help with this.


Boulderdash(Posted 2016) [#3]
Thank you for your reply, I understand now that's its to do with translating to Java, some kind of limitation.


Gerry Quinn(Posted 2016) [#4]
It may be just that most of the targets have Java-style rather than C-style arrays. Or maybe Mark just likes them better.

A lot of the time it won't matter anyway, and if you really want to you can use 1D arrays for speed, even without inlines.

Anyway you can add the class above or roll your own class or functions to get rid of the annoying long-winded allocations, Once they're allocated, usage is the same as with C-Style except that you can't hop around using relative indices across multiple dimensions.