Here's a tech tip for the more adventurous among you, who'd like to learn a faster, shorter way to code repetitious actions on similarly named variables or I/O.
A recent post on the OptoForum asked for an OptoScript equivalent to Eval(), a function used in a variety of programming languages, typically to act on expressions or operators passed in a string.
We won't get into the question of whether Eval() is "evil" or not (apparently it has a reputation for trouble in more than one language). Instead, we'll move right into how you can do good things by using a similar approach in your PAC Control strategy—and clean up a lot of spaghetti code in the process.
In this Forum case, a large number of tags in the poster's strategy had similar names (Digi0, Digi1, and so on). The same value was applied to each tag individually—which meant a lot of code.Fortunately, when you have several similar tags that need similar logic, PAC Control gives you options for grouping them to automate your automation logic:
- If you have several related integers or floats, you can use a Numeric Table.
- For a set of names, labels, or the like, you can use a String Table.
- Or if you need to loop through different types of tags (like all the I/O units in your strategy), you can use a Pointer Table. (A good example is this handy Product Support-recommended chart, which regularly loops through all your I/O units to maintain communication with them.)
Check out the reply in the OptoForum post to see or join the discussion.
One caveat: If someone changes the names (for example, if Digi0, Digi1, and so on became Pump0, Pump1, etc.), this logic will break. That’s why you’ll notice a check for null in the example.
So remember: You always have multiple options for writing your control logic, and it’s always a good idea to check on the OptoForums for some you might not have known!