Arrays as Object Properties

From SCI Wiki
Revision as of 12:45, 11 August 2013 by Andrew Branscom (talk | contribs)
Jump to navigationJump to search

According to Lars Skovlund:

"There is no way to do what you ask. That's part of the reason why they had to introduce the Memory call in SCI01 (but that's an ugly solution to the problem. There is a hack that you can use, however. Declare a single local variable followed by the arrays you need. Then you can (at least from the point of view of the PMachine, not sure about Brian's compiler) index into the large arrays by addressing the lone local variable and using a bit of arithmetic."

Code:
(local
  baseVar
  array1[10]
  array2[10]
)

(instance Blah of Obj
  (properties
    arrayPos 1
 )
)

(instance Blarg of Obj
  (properties
    arrayPos 11
  )
)

 

To access the array, you use a reference like:

Code:
  baseVar[(Blah:arrayPos)]     // Gets the 1st value from array1
  baseVar[(Blarg:arrayPos)]    // Get the 1st value from array2

  baseVar[+ (Blah:arrayPos) 1]     // Gets the 2nd value from array1
  baseVar[+ (Blarg:arrayPos) 1]    // Get the 2nd value from array2