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.

Testing if a global var exists

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Testing if a global var exists

Post by miljbee »

Hello,

In a python script, I would like to test if a global var exists.

Something like :

if eg.globals.somevar exists:
eg.TriggerEvent(eg.globals.somevar)
else:
eg.globals.somevar="default"

Can you tell me how to write the bold line ?

Thanks !
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Testing if a global var exists

Post by Pako »

Code: Select all

if "somevar" in eg.globals.__dict__:
    eg.TriggerEvent(eg.globals.somevar)
else:
    eg.globals.somevar="default"
Pako
miljbee
Experienced User
Posts: 146
Joined: Fri Mar 27, 2009 1:29 pm
Location: Orl├®ans, France

Re: Testing if a global var exists

Post by miljbee »

thank you !
miljbee
TCP Events : A Better Network Event Sender/Receiver Plugin.
The Network Event Sender/Receiver in C#
Get events in EG from Google Calendar.
kalia
Experienced User
Posts: 109
Joined: Wed Aug 12, 2009 1:10 am

Re: Testing if a global var exists

Post by kalia »

Thanks Pako.

I always wondered about this also, but never asked.
Post Reply