1. Re: How can I work with a user type arra

Your cell/item tuple can be represented by the sequence:

     { cell, item }

Data types in sequences do not have to be declared. You could define a
prototype (default) your type as:

  constant myType = { 0, 0 }.   -- default item
  constant CELL = 1,            -- index to first value
           ITEM = 2.            -- index to second value

You can use 'myType' like this:

   sequence x            -- declare the variable
      x = myType                -- assign it to your data structure
      x[CELL] = 22              -- same as x[1] = 22
      x[ITEM] = 33              -- same as x[2] = 33

But I digress. You can then create a 2D array using the repeat() command:

   global sequence mapVar           -- this will be your array
   mapVar = repeat( myType, 100 )   -- 1 row = 100 cols of myType
   mapVar = repeat( mapVar, 100 )   -- matrix = 100 rows of cols

More typically, you can embed the repeat(), like:

   -- more typical; though not very readable IMHO.
   mapVar = repeat( repeat( myType, 100 ), 100 )

and even hard code myType:

   -- even more typical. bad style, though, IMHO.
   mapVar = repeat( repeat( {0,0}, 100 ), 100 )

Once the array is created, you can then assign values like this:

   mapVar[2][3][CELL] = 3   -- row 3, col 2, index 1 of myType
   mapVar[2][3][ITEM] = 4   -- row 3, col 2, index 2 of myType


Hope this helps.

 -- David Cuny

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu