New guy here. In searching through the forum and WIKI I have found many references on the use of a global variable, but have been unable to find how to implement one. Any help would be welcome.
Do a search on “Global Variable” and you will find threads with examples on how to declare them. You will also find reasons why you might want to use Virtual Devices instead (global variables are lost during a reboot).
Search on “Virtual Devices” for information on Virtual Devices.
I find snipits of code like - global_party_mode_flag = 1. Is this all that is needed or does one have to establish a “flag” first.
You are correct.
“global_party_mode_flag” is the variable name (in your example).
I use the naming convention global_(variable_name) to remind myself I intend the variable to visible to all functions and scenes on the Vera, and to avoid confusion with like named local variables. You do not need to add the global_ prefix to your variable name to make it global.
Variables are global scope in scope unless declared as local. See http://www.lua.org/manual/5.1/manual.html#2.3 for more information.
Thanks all for the info.
Please can anyone assist. i’m still struggling to make use of a global variable.
I wish to run a scheduled bit of code that stores a “global” variable whose value i wish to obtain when running the code at a later time. Ive read the previous posts but it still seems like my variable is lost outside of my code.
How can i set a value to retained in my vera to be recalled for later access?
The only persistent state is for a service variables on a device.
There are NO really global variables. The code for every plugin that provides the behavior of the device run’s in it’s own namespace … Multiple devices from the same plugin each have their own namespace. If you want to share data globally you need to use service variables … or some external source such as a web service.
I guess another approach would be to use the plugin “Variable Container”.
I guess another approach would be to use the plugin "Variable Container".The Variable Container provides a place holder for Service Variables with an associated GUI.
But you do not really need it … I have attached additional state to many of my devices.
Vera does not care if you create additional variables on an existing device … In fact it provides a facility for you to do this in the advanced tab.