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.

Python - how to do an if else with value in variables?

If you have a question or need help, this is the place to be.
Post Reply
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Python - how to do an if else with value in variables?

Post by Mastiff »

I need to check if a variable called "eg.globals.Kanal" (radio channel) is Stopp or not. If the value is Stopp I want to set a variable that turns off the amp in the next action, if not (in other words if it's one of the radio channels) I want to set another variable that turns it on. But how do I do that? I tried the simple way, which didn't work:

Code: Select all

if eg.globals.Kanal not 'Stopp':
    eg.globals.Forsterker = Paa
elif eg.globals.Kanal is 'Stopp':
    eg.globals.Forsterker = Av
I would appreciate a tip on how it's actually done. As usual I can't code myself out of a brown paper bag, even if it's soggy! :oops:
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Python - how to do an if else with value in variables?

Post by krambriw »

Code: Select all

if eg.globals.Kanal <> 'Stopp':
    eg.globals.Forsterker = Paa
or

Code: Select all

if eg.globals.Kanal != 'Stopp':
    eg.globals.Forsterker = Paa

Code: Select all

elif eg.globals.Kanal == 'Stopp':
    eg.globals.Forsterker = Av
:D
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: Python - how to do an if else with value in variables?

Post by Mastiff »

Thanks! Even modified it a bit:

Code: Select all

if eg.globals.Kanal == 'Stopp':
    eg.TriggerEvent ("Ingenting")
else:
    eg.TriggerEvent ("Main.Badet_Forsterkerpaa")
So when the radio channel is stopped, nothing is done (I turn off the amp with another button), but when there is a radio channel started I trigger an event that will turn on the amp (if it's not already turned on, this is a discrete on).
Post Reply