Device ordering within a string

variables

#1

1) Give a description of the problem
I have a number of device tiles - e.g. Presence. when populating the devices in the device variables via the IDE UI e.g. Presence and PresenceNames - the order appears to be based on the order they appear to webcore (not necessarily alphabetical).

2) What is the expected behavior?
I’d like to be able to put devices that are set in a variable string in my own arbitrary order: “Dev 1, Dev6, Dev 2” etc

3) What is happening/not happening?
(PUT YOUR INFO HERE)
When ticking the items in the UI, the string is updated with the names as they appear to the UI

4) Post a Green Snapshot of the pistonimage
(UPLOAD YOUR IMAGE HERE)
Nothing helpful to paste here

5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS THEN HIGHLIGHT ALL OF THE LOGS SND CLICK ON THE </> ICON TO FORMAT THEM)
n/a


#2

My device tile pistons do exactly what you want. When I get a chance, I’ll post an example.


#3

I stripped this piston down to the basics to focus on the mechanism of ordering the tiles. Obviously this can be applied to a variety of device types.

Hopefully this was what you were looking for.

Edit: Minor correction to original piston.


Cant figure the weather out
#4

Thanks @bthrock. I’ll give this a go when I get a chance.

I was trying to follow the code, and there’s something i don’t understand.
In the for loop you use the values of currentDevice, currentTile and tileClickDevice, but I don’t see them get updated to reflect the next value in the loop.
Is this some voodoo of the way pistons work that variables in a define block will always be up to date without needing to be explicitly updated in each iteration of the loop on ‘index’


#5

Not really voodoo. Those variables are dynamic and defined by an expression, therefore they will be reevaluated each time the variable is referenced in the body of the piston.

This method of defining variables can sometimes be useful for decluttering pistons and preventing syntax errors by eliminating unnecessary ‘set variable’ statements and/or the need to repeat a complex expression multiple times in the body of a piston.

In this instance, I would either have to add three ‘set variable’ statements in the body of the piston, or place the formulas into the body of the piston tile statement, which would make it much harder to read.


#6

Thanks. I’ve not done any real coding in years…maybe a bit of vbscript/powershell and turbo pascal back in the day…so setting variables in loops is second nature…this way is new to me, but i see the benefit