1) Give a description of the problem
I want to have two list variables. The first would be strings, corresponding to the values passed from a remote hub calling piston (via URL). The second would be devices, each entry being a device on my local hub. I want a clean, straightforward way to use the calling argument to find the matching entry in the first (string) list (collection), and then use that entry number to refer to the corresponding entry in the second (devices) list.
2) What is the expected behaviour?
/* Pseudo-code, I realize this isn't necessarily completely correct syntax
define
string SearchList "Mirror1"; "Mirror2"; "Mirror3";
devices DeviceList Switch1, Switch2, Switch3
integer DeviceIndex
Do
-- See which entry in SearchList array matches the argument we received
DeviceIndex = LocationOf ({args.1}, SearchList);
-- If a match was found, use the corresponding entry in DeviceList
-- to perform some action
If DeviceIndex <> 0 then
With DeviceList.DeviceIndex
-- perform some action on the device
End If
End Do
I can do this with brute force, but I’m hoping to do something a lot more concise, a lot clearer, and a lot easier to maintain by just updating the two arrays.
Brute force method
Do
Case
When {args.1} = "Mirror1"
-- perform some actions with Switch1
When {args.1} = "Mirror2"
-- perform some actions with Switch2
When {args.1} = "Mirror3"
-- perform some actions with Switch3
End Case
End Do
The actions I want to perform are identical for each device and are more extensive than just a line or two of code. So it’s a real nuisance to repeat almost-identical code in ever CASE condition, and error-prone when I have to update the actions.
I suppose I could iterate through the SearchList, counting as I go, until I get a match, and then use that count to reference the necessary entry in DeviceList. But I’m hoping there’s a more elegant solution.