[dirGames-L] Multidimensional Arrays using Lingo

Thomas Kaiser tom at meisterkaiser.de
Tue Oct 11 02:02:01 EDT 2005


Hi Ryan!

Rac> int g_bBoard [ 3 ] [ 3 ] ;

What you'd need to do here is to create an empty list and populate it
with lists or default values before setting and retrieving values...
Somethig like this should work:

on createBoard (xDim, yDim, defaultVal)

   tmpBoard = []
   tmpY = []
   
   repeat with i = 1 to yDim
     tmpY[i] = defaultVal
   end repeat

   repeat with i = 1 to xDim
     tmpBoard[i] = duplicate(tmpY)
   end repeat

   return tmpBoard

end

g_bBoard = createBoard(3,3,0)

Rac> g_bBoard [ 0 ] [ 0 ] = 1 ;
Rac> g_bBoard [ 0 ] [ 2 ] = 2 ;
Rac> g_bBoard [ 2 ]  [ 0 ] = 1;
Rac> g_bBoard [ 2 ] [ 2 ] = 2 ;

Then this should work perfectly! (Just in case you don't know already:
Mind the use of the duplicate() function - Lingo will pass all parameters
as value EXCEPT lists wich will be passed as reference by default. Omitting
the duplicate will therefore result in g_bBoard populated by three identical
instances of the same list.)

There may be more elegant ways of poing the initialising, but this should get
you started ...

Cheers,
tom



More information about the dirGames-L mailing list