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.

Persistent variables - save/restore variable value on restar

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
TRIROG1
Posts: 45
Joined: Fri Aug 08, 2014 10:07 pm

Persistent variables - save/restore variable value on restar

Post by TRIROG1 »

Hi!

Is it possible to somehow save the value of a certain variable so that when i restart the EG, the state of variable is not lost?

e.g. if i assign a eg.globals.myVar = 1 and then restart the EG, the myVar variable no longer exists. What should i do to save that variable?
Is writing it to a file an only way?

Thanks!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Persistent variables - save/restore variable value on re

Post by Pako »

Here are two of the ways to solve it:
  • Check the file FindWindow.py (it's part of the plugin Window).
    There search for the keyword "eg.PersistentData" and see how it treats the variable "hideOnDrag".
  • You can use the Webserver plugin or Tornado plugin (which actually no, if you do not like it)
    and actions "Set persistent value" and "Get persistent value".
    It is not necessary to use these your variables as well as inside Webserver/Tornado plugin.
Pako
juanson
Posts: 10
Joined: Tue Dec 11, 2012 3:11 am

Re: Persistent variables - save/restore variable value on re

Post by juanson »

I've done it like this:

eveything on the Auto Start (i have it in spanish, i don't know exactly the words so i'll try to explain myself).

1- Python Script:

Code: Select all

eg.globals.Dashboard_X1 = "0"
with each variable. IT CREATS THE VARIABLE.
2- Create a Folder and in it one file.txt for each variable. SOMETHING THAT IT'S NEEDED FOR THE NEXT STEP.
3- Python Program

Code: Select all

f0 = open("C:\...................\EG_variables-DASHBOARD_A1.txt","r")
data = f0.readlines(0)
eg.globals.Dashboard_A1 = data[0]
f0.close()

f1 = open("C:\...........\EG_variables-DASHBOARD_A2.txt","r")
data = f1.readlines(0)
eg.globals.Dashboard_A2 = data[0]
f1.close()
and so on.
IT READS THE 1ST LINE OF THE SPECIFIC FILE AND TURNS WHAT IT'S WRITTEN ON IT IN TO THE VARIABLE.

TO WRITE THE VARIABLE ON THE FILE Not in start up

Code: Select all

w = open("C:\.......................\EG_variables-DASHBOARD_B4.txt","r+")
w.write("THE VARIABLE")
w.close()
Hope it helped
TRIROG1
Posts: 45
Joined: Fri Aug 08, 2014 10:07 pm

Re: Persistent variables - save/restore variable value on re

Post by TRIROG1 »

Great!
Juanson:
thanks for this tip regarding the save to file method.

Pako:
I looked at the hideOnDrag, but unfortunately it doen't tell me much.

Would you be so kind and help me with an example please?

Btw:How can i remove/delete a persistent variable from the tornado?

Kind regards to all!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Persistent variables - save/restore variable value on re

Post by Pako »

TRIROG1 wrote:I looked at the hideOnDrag, but unfortunately it doen't tell me much.
There you can see everything what is needed.
Maybe you are missing some python skills. This is not the appropriate place to address this problem.
TRIROG1 wrote:Btw:How can i remove/delete a persistent variable from the tornado?
TornadoPerVarManager.png
TornadoPerVarManager.png (10.15 KiB) Viewed 4330 times
Pako
TRIROG1
Posts: 45
Joined: Fri Aug 08, 2014 10:07 pm

Re: Persistent variables - save/restore variable value on re

Post by TRIROG1 »

Of course i'm still a beginner ... but hey ... gotta start somewhere ;)

Thanks!
Post Reply