Array index - any tricks for using numbers or strings?
Posted: Thu Mar 11, 2010 4:32 am
I am creating an application in RR that reads another application file format. I have a global variable array that contains a one word string and is indexed by a number value. Each item is used in my application might need to be looked up as either a word or a number. Unfortunately RR can't use the string value as the index or the number as the index interchangebly. In some places I only have a number value to look up the "word" but in some places I have the "word" that needs to get the number.
As a workaround and since the list is small, I have two duplicate sets of values in the array. My question is if anyone has a way or technique to doing some kind of cross referencing that might work so I don't have to include double sets of indexes in my array. The good news is this is just a curiosity for me at the moment... to be efficient. This array will be set once and is static and never changes. It contains static unchanging values and is a way to quickly find the type of info the number or word represents so it can be "written" to an exported file format.
I am using a single function, that I pass either a number or word from the file format and return either a number or word back depending on what is needed.
Below is the array indexed by number values:
(And YES, number 8 is "missing". Don't ask me why. There are only 8 layer types in the file format but 8 is not used for some reason I don't know. The "Sound" layer type was just added in the latest version so that might be a reason.)
Duplicated reversed array entries:
And this is my simple function:
So I am wondering if this is a reasonable solution or is there a better one?
As a workaround and since the list is small, I have two duplicate sets of values in the array. My question is if anyone has a way or technique to doing some kind of cross referencing that might work so I don't have to include double sets of indexes in my array. The good news is this is just a curiosity for me at the moment... to be efficient. This array will be set once and is static and never changes. It contains static unchanging values and is a way to quickly find the type of info the number or word represents so it can be "written" to an exported file format.
I am using a single function, that I pass either a number or word from the file format and return either a number or word back depending on what is needed.
Below is the array indexed by number values:
(And YES, number 8 is "missing". Don't ask me why. There are only 8 layer types in the file format but 8 is not used for some reason I don't know. The "Sound" layer type was just added in the latest version so that might be a reason.)
Code: Select all
aLayerTypes[1] -- contains "Vector"
aLayerTypes[2] -- contains "Image"
aLayerTypes[3] -- contains "Group"
aLayerTypes[4] -- contains "Bone"
aLayerTypes[5] -- contains "Switch"
aLayerTypes[6] -- contains "Particle"
aLayerTypes[7] -- contains "Note"
aLayerTypes[9] -- contains "Sound"
Code: Select all
aLayerTypes["Vector"] -- 1
aLayerTypes["Image"] -- 2
aLayerTypes["Group"] -- 3
aLayerTypes["Bone"] -- 4
aLayerTypes["Switch"] -- 5
aLayerTypes["Particle"] -- 6
aLayerTypes["Note"] -- 7
aLayerTypes["Sound"] -- 9
Code: Select all
function LayerTypes layerVal
if isNumber(layerVal)
return aLayerTypes[layerVal]
else
put quote & layerVal & quote into layerVal
return aLayerTypes[layerVal]
end if
end LayerTypes