Logic script - 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: Logic script (/showthread.php?tid=61) |
Logic script - tlandeka - 13.08.2015 Hello, I need group address which will show if any of windows is opened. So, I made event-based script, but problem is that only one event (window) affect result. How can I make script that will send result if any of windows open? Thank you RE: Logic script - Pawel - 13.08.2015 post code, it will help us to understand the problem RE: Logic script - tlandeka - 14.08.2015 There is no special code... For example, here is logic "a = b and c and d". If I use event based scripting, only change of one group address (for example "b") will change "a", but I need script where change of "b","c" or "d" will change "a". This is because I can choose only one "group address/tag" on which the script will be triggered. In concrete situation, lets say there are 5 windows, and I want to have object which will show "ON" if any of window is opened, and "OFF" if all of them are "OFF". So this object will change it state if any of this window. It is the most basic logic. RE: Logic script - gtsamis - 14.08.2015 You can tag objects b,c,d and make a script that runs on specific tag. your script should look like: Code: b = grp.getvalue('5/1/2') RE: Logic script - Sandstrand - 17.08.2015 This is a perfect use case for TAGS in LogicMachine For every window you have assign a tag to it, then set a resident script that checks the tags and performs some logic on it. example: Code: myobjects = grp.tag('ABC') The above scripts checks every n seconds boolean group adresses with the tag ABC, then sets 1/1/1 to true if one of the tags are true. No need to create a huge script with declarations for each and every group address, just tag the object and this will fix it. There are most likely other ways to do this, but I'm still learning LUA and would love to see other implementations Added bonus here is that you also get a count of how many windows that are open. RE: Logic script - admin - 18.08.2015 You can make it a little bit smaller by replacing this: Code: if (a > 0) then With this: Code: grp.write(myobject, a > 0, dt.bool) If you need AND instead of OR you can do this: Code: grp.write(myobject, a == #myobjects, dt.bool) RE: Logic script - Sandstrand - 18.08.2015 Thank you for that elegant (a > 0). Also didnt think of the # operator, was abit sceptical to use it with the whole true / false / nil statement. Will a false also show as a nil when it comes to the #? Would it be better to replace it with table.getn(myobjects) since that one cant suddenly stop on a nil value and end the statement like # (according to some other forums). RE: Logic script - admin - 18.08.2015 objects table is guaranteed a be normal array without any holes (nil elements), so # operator does the same as table.getn From Lua manual: Both nil and false make a condition false; any other value makes it true. |