unpack array in spin
stargazer2050
Posts: 89
Need syntax to unpack array in spin
Repeat var from o to 5
Get result
Put them in individual variables, var1, var2 ...
Repeat var from o to 5
Get result
Put them in individual variables, var1, var2 ...
Comments
This should have been asked in the Propeller forum.
The answer of course is still the same which Mike gave.
The answer to this:
is you can't from within a loop like that. Well you can if you use pointers but then you might as well leave it in an array. To use unique variable names for each element, you need to do it the way Mike demonstrated.
What I do, is leave it in an array and have meaningful constant names to refer to the various elements.
For example, the program I'm working on right now, I use:
(The "#0" means assign the first constant listed to zero and increment each constant from there.) Then I access the elements with these constants:
Need expression term with '0 to rx_channels'
Instruction or variable with 'channel'
Then you're using functions of some sort for some reason.
Well, i tried. If it gets a workin please let me know.
Thankyou both very very.
This was an example to show why don't really need to unpack an array. I was showing you the way I name things in general. I didn't include enough of the program to compile it.
This line of code could be thought to "unpack" one of the elements of the array:
But it isn't really need, since I could just use "channel[ROTATE_CHANNEL]" instead of "rotation" in any of my calculations.
channel[ROTATE_CHANNEL] is the same as channel[3], but I think it's easier for me to understand the meaning of the channel[ROTATE_CHANNEL] than channel[3] when I look back at the program.
Why is "rcVar1" better than "pulseLength[0]"? You could even rename the array "pulseLength" to "rcVar". If you don't like using a zero index add one to the array size and start your numbering at one instead of zero. If you rename and start with one instead of zero then you'd just use "rcVar[1]" instead of "rcVar1". This lets you access each variable with loops and all sorts of other advantages.
One of the reasons to use an array is so you don't have to do silly inefficient things like having rcVar1, rcVar2, rcVar3, etc. If for some reason you want a second set of data use another array and use "longmove(@rcVar, @pulseLength, NUMBER_OF_LONGS_TO_COPY)".
Thanks again!!