more G-Labs products

Author Topic: Wizard Scripting: Setting a globally available variable  (Read 2385 times)

April 20, 2015, 10:48:47 AM
Read 2385 times

Ossi_Jr

  • *
  • Information
  • Newbie
  • Posts: 8
Hi,

I am thinking about some kind of absence mode. Where different nodes in my network behave differently based on the fact I am absent or not. Therefore I'd like to create a global variable which can be used in the triggering section (sth like isAbsent = false).
But I have to idea if there is a way to create such a variable to be available in every program?

Is it achievable? If not via scripting, is it possible to create such a variable with one of the language programming?

Cheers and thanks

April 22, 2015, 11:38:34 AM
Reply #1

Ossi_Jr

  • *
  • Information
  • Newbie
  • Posts: 8
Am I really the first one thinking about such a requirement?

April 22, 2015, 12:23:39 PM
Reply #2

Peter1977

  • *
  • Information
  • Newbie
  • Posts: 24
I don't think its posible but i would love that feature.

April 22, 2015, 05:02:41 PM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
You can access the value of a parameter from any program by properly referencing it.  There is no easy way to add such a global variable to the main HG code, but there is really no need for it either.

April 22, 2015, 05:40:08 PM
Reply #4

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330

There is a PingMe.AtHome app/program in the Security group which would give you a good starting point of using an event/parameter:
Code: [Select]
//setup
  Program.Parameter("PingMe.AtHome").Value = "1";
//code
    if (pinging_buddies > 0 && Program.Parameter("PingMe.AtHome").Value != "1")
    {
        Program.RaiseEvent("PingMe.AtHome", "1", "Ping Me At Home");     

If I understand how this particular app works, you would need to have your router assign a fixed IP to your cellphone so the app could ping it reliably.  Also would require WiFi on cellphone to be on as  you arrived home.

April 23, 2015, 04:28:49 PM
Reply #5

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Forgot about that script, but that would definitely get the OP ~95% of the way to where he wants to be.  It might require tweaking the script a little to do his task or just writing another script that uses the PingMeAtHome parameters.

May 06, 2015, 02:57:29 PM
Reply #6

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
Another option to have a variable that sticks around and is globally accessible is to write to a file, then read when needed.  May be useful, for example, if one wanted to remember if the alarm system was on or not across a reboot/power outage.

May 06, 2015, 08:40:35 PM
Reply #7

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That would certainly work.  If you are writing a value that doesn't change much or need to be accessed quickly, that would work well.  If it's being written all the time and/or needs fast access time, that might not be the best option.  Good suggestion!

May 07, 2015, 12:04:41 AM
Reply #8

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
Global variable can be access by program. You can create therm by calling :

Setting.Parameter("VariableX").Value = "Any value" ;

It's can be called by any program. Only we cannot access from UI.