arrayItem Issue


#1

1) Give a description of the problem
I have a device named devs that has 6 devices in it. I want to use a FOR statement with arrayItem to individually get the power for each device by using arrayItem by doing this in an expression of a condition in an IF statement:

[arrayItem($index,devs):power]

but when I do that, I get an error message. See the attached screen capture. If I replace arrayItem($index,devs) with a device name, then the condition works. Do I need to somehow declare arrayItem($index,devs) to be a device for which I can get :power?

2) What is the expected behaviour?
interpret arrayItem($index,devs) to be a device

3) What is happening/not happening?
I get an error message.

4) Post a Green Snapshot of the pistonimage

Here is the device declaration:

DeviceList

5) Attach logs after turning logging level to Full
No logs. Webcore will not compile that statement because of the error.


#2

Instead of arrayItem, have you tried just iterating like below…

for each ($device in devs)
do
  log to console [$device:power]
end for each

#3

Well, I could do that if all I wanted to do was access that dev list. But I need an index value so that I can index into a 2nd list of devices based on the criteria for the 1st. Here’s an pseudo example:

For index from 0 to 5 step 1
if {[devlist1(index):power]} is <10 then
if {[devlist2(index):switch]} is ON then
do something
endif
endif
next index


#4

I will have a look.

Another choice is to assign the arrayItem(RRindex,devs) to another device variable, then use that for your attribute evaluation


#5

Thanks for that suggestion. It works great!