Logic Machine Forum
save mode to array and modify - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: save mode to array and modify (/showthread.php?tid=5522)



save mode to array and modify - legolas2069 - 19.07.2024

Good morning.

Let's see if you can give me a hand, I haven't touched the scripts in a while and I'm having a hard time getting my bearings.

I have 160 objects with 5 different modes, from 1 to 5, and the user is going to assign a number to each object in the visualization. Then, I have 5 objects, one for each mode, that will perform an action on those 160 objects, according to the assigned number of each one. For example, if there are 34 objects with the number 3, I will make a script that sends X value to those 34 objects.

To do this, I think the best way is to create an array that saves the mode state of those 160 objects, and when one of those objects is modified, the array is traversed, and only the corresponding position is modified.

The question I ask you then: How can I make that array with the reading of the objects and the subsequent modification?

Thanks for your help.


RE: save mode to array and modify - admin - 19.07.2024

Create virtual objects that will contain the selected modes. Use an addressing scheme that allows to easily calculate the output object address. For example output is 1/2/3 and mode is 32/2/3. Assign a common tag to all mode objects.

Event script example where event value is the selected mode. Only objects where the mode is the same as the event value are affected.
Code:
value = event.getvalue()
objects = grp.tag('mode')

for _, object in ipairs(objects) do
  if object.value == value then
    output = object.address:gsub('^32/', '1/')
    grp.checkwrite(output, 123)
    os.sleep(0.1)
  end
end



RE: save mode to array and modify - Daniel - 22.07.2024

Share your script, maybe there is a way to make a single one for all.


RE: save mode to array and modify - legolas2069 - 22.07.2024

Hi!
I have deleted the previous message because it was not entirely clear. admin, thanks for the help, but I'm late because I had already made all the objects, and changing them now would be cumbersome.

 I'll try to explain it:

I have 160 lights. Each of these luminaires will have 3 operating modes, as if they were DALI groups, and the user will be able to assign the group as needed (only 1 group for each luminaire). Next, when the user wants to turn on the luminaires of a group, the system will have to know which group those luminaires belong to, and turn on the corresponding ones.

Thanks in advance for your help.