Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Difference between temporary and persistent variables?

If you have a question or need help, this is the place to be.
Post Reply
wysocki
Experienced User
Posts: 65
Joined: Mon Nov 23, 2015 9:23 pm
Location: Los Angeles area

Difference between temporary and persistent variables?

Post by wysocki »

I want to monitor the open/closed state of my garage door on a page in the webserver. I get X10 events (CM11A.D2.on and CM11A.D2.off) if the door is up or down respectively. On those events, I plan to create a macro to broadcast the new state of the door. However, because someone could start a browser in between events, I believe I need to set a variable in those macros so that I can immediately display the current state of the door by just coding the string {{garagedoor}} in my html.

However, I'm confused about variables (really!). I created a test macro like this:

Code: Select all

Webserver: Set persistent value: testvar1: Apples
Webserver: Set temporary value: testvar2: Bananas
Webserver: Broadcast values: testvar1,testvar2
The test script in my html contains:

Code: Select all

function wsMessage(event) {
   var obj = JSON.parse(event.data);
   document.getElementById("var1").innerHTML = obj.kwargs.testvar1;
   document.getElementById("var2").innerHTML = obj.kwargs.testvar2;
   document.getElementById("all").innerHTML = event.data;
}
The temporary variable (testvar1) always is received as "null":

Code: Select all

{"method": "Values", "kwargs": {"testvar1": null, "testvar2": "Bananas"}}
Why does the "persistent" variable show up as null but the "temporary" variable broadcasts properly?
But if I do a "Webserver: Broadcast all values" both variables are received correctly (including a bunch from MusicBee and others).
Could someone please explain the differences in those two types and why this happens?
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Difference between temporary and persistent variables?

Post by Pako »

wysocki wrote:Difference between temporary and persistent variables?
The explanation is simple.
Persistent value is retained even after closing and reopening (restart) EventGhost program.
wysocki wrote:Why does the "persistent" variable show up as null but the "temporary" variable broadcasts properly?
There is also a simple explanation. That was a bug. I never use persistent values, so I never met with it. In the opening post of Webserver plugin topic you can download the patched version.

Pako
You know flattr ? You can Image
Post Reply