Arrays as Object Properties (SCI): Difference between revisions

From Sierra Wiki
Jump to navigationJump to search
No edit summary
 
m (1 revision imported)
(No difference)

Revision as of 23:26, 2 June 2024

Arrays as Object Properties



Introduction

With SCI0 you cannot set properties within an object with arrays.

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.

SCI Code:

<syntaxhighlight lang="sci"> (local baseVar array1[10] array2[10] )

(instance Blah of Obj (properties arrayPos 1 ) )

(instance Blarg of Obj (properties arrayPos 11 ) )

</syntaxhighlight>

To access the array, you use a reference like:

SCI Code:

<syntaxhighlight lang="sci"> 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

</syntaxhighlight>


References


Also See