Global variables

Hi,

I have just purchased Flowbotics and am looking into developing my application. Is there a way of declaring global variables? For example, I may have a file name which I want to use from various components, without having to have explicit links.

Hi,

You can setup global variables in Ruby by using the $ sign in front of the variable name. Please note that use of global variables is discouraged in most cases and you should instead rely on the inputs / outputs. If you wish to now have too many “wires” going to / from modules, you can also use the wireless link component to move data from various modules at different depths. This allows you to do a similar effect as global variables without loosing the links / connections. Global variables are harder to maintain in code for the long term.

We have attached a screen shot of an example to this post and also the example project the screenshot is taken from. Simply change the integer value on the top left and click the button to trigger an update of the global variable (using the Ruby module). Then, click the bottom button to trigger and event. The second Ruby module will then output the global to the integer number on the right.

Sincerely,
Global Variable Example.fsp (19 KB)
Global Variable Example.png

Thanks. What I actually want to do is use the schematic in different “modes”, such as to either run on the PC locally or create an XML configuration or monitor a remote system. I thought one way to do this was to declare a global variable with values LOCAL, CONFIGURE or REMOTE, then within the ruby component of all my modules I could do different things based upon this global.

But if there is a better way of doing it, do let me know.

Hi,

The use of a global variable for a project-wide configuration is one of the few cases where it is (somewhat) safe to use. We would still prefer the use of the wireless link (to find it, simply search for “wireless” in the search bar in above the component list), since it is more easily traceable (you can select the component and then press “TAB” to iterate through all the modules that use it).

Since you seem to imply that all your modules will need this “mode switching” capability anyways, the Ruby global variable might actually be the best solution to your problem.

Since your project sounds interesting and probably complex (to new users of FlowBotics Studio), we suggest that you post on the forum as you make progress (on a new thread dedicated to your project). This could both allow you to help others learn from your project and also receive input from the community here.

Sincerely,