Array Access Help
soshimo
Posts: 215
Okay, I'm butting my head up against the wall trying to provide a public function which returns a value based on an index passed in - the index is an index into an array. The code works fine when I use an actual constant as the index to return a value from the array but as soon as I try to use the value passed in I get a very large number, and it's the same regardless of what index I'm using.
This is a public function in an object that I created.
Here is some sample code that actually works:
And here is code that does NOT work
Here is how I delcare inputValues:
I really don't want to have to put a case statement in there to return the values directly and the array access should work with a variable - or maybe I missed something in the manual, but there are other cases where I use a variable. In fact, in the same object causing problems I have an array of indices into another array (because I couldn't figure out how to do multi-dimensional arrays). TIA
This is a public function in an object that I created.
Here is some sample code that actually works:
' **************************************************************** ' * GetInputValue * ' * Get previously stored value * ' **************************************************************** PUB GetInputValue(index) return inputValues[noparse][[/noparse]ABUTTON]
And here is code that does NOT work
' **************************************************************** ' * GetInputValue * ' * Get previously stored value * ' **************************************************************** PUB GetInputValue(index) if( index >= 0 and index < MAXINPUTINDEX ) return inputValues[noparse][[/noparse]index] else return 0
Here is how I delcare inputValues:
CON MAXINPUTINDEX = 8 VAR long inputValues[noparse][[/noparse]8]
I really don't want to have to put a case statement in there to return the values directly and the array access should work with a variable - or maybe I missed something in the manual, but there are other cases where I use a variable. In fact, in the same object causing problems I have an array of indices into another array (because I couldn't figure out how to do multi-dimensional arrays). TIA
Comments
Here is what I have for the CON section in the object:
And here is my call:
I think the pantilt#ZBUTTON is what is incorrect. What is the proper syntax for referring to an objects constant values?
Again, TIA.
I found the error with the following debug-strategy:
CHECK EVERY SINGLE DAMMED DETAIL BY DEBUGOUTPUT
this code lead me to the bug
debugoutput
right at the beginning parameter index contains the right value
after the if-condition it's "-1" all the time
aha there happends something inside the if-condition
it is the "index >= 0"
exactly the ">=" is the bug
the equal-sign BEHIND the greater sign means store result into variable index
the correct notation for the condition is equal or greater is
"=>" the equal-sign must be written INFRONT of the greater-sign
here the complete democode from my debugging
debugoutput
best regards
Stefan
P.S.: I tested the syntax "objectname#constantname
it seems to work
Post Edited (StefanL38) : 12/26/2008 1:01:56 AM GMT