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.

if or else or goto or break or label...

If you have a question or need help, this is the place to be.
Post Reply
eddiex666
Posts: 41
Joined: Fri Sep 12, 2014 10:34 pm

if or else or goto or break or label...

Post by eddiex666 »

Hi,

I am trying to create a simple phython script..

1)
how can I create a if this do this or else do that :-)
if var = ('yes')
do turn on
else
do turn off


2)
Hos can I use goto or labels?
if var=(''yes') goto yes
if var=('no') goto no
goto end

:yes
do turn on

:no
do turn off

:end


I am very newbee to python, so any help will be good...


Eddie
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: if or else or goto or break or label...

Post by krambriw »

@eddie,

You do not jump to labels, btw that is really ugly and bad habits in all programming languages.
http://stackoverflow.com/questions/1886 ... -in-python

Do function calls instead like in the examples below

The first and second in python

Code: Select all

def doTurnOn():
    print 'Turn On'


def doTurnOff():
    print 'Turn Off'


var = raw_input("yes to turn on?")
if var == "yes" or var == "Yes":
    doTurnOn()
else:
    doTurnOff()

Code: Select all

def doTurnOn():
    print 'Turn On'


def doTurnOff():
    print 'Turn Off'


var = raw_input("yes or no?")
if var == "yes" or var == "Yes":
    doTurnOn()
elif var == "no" or var == "No":
    doTurnOff()
print 'End'

eddiex666
Posts: 41
Joined: Fri Sep 12, 2014 10:34 pm

Re: if or else or goto or break or label...

Post by eddiex666 »

cooool this is working, and i am agree, do call is better..


BUT...

I try to call a even with eg.EventTrigger('Event')
But is does not work...

I can run the trigger manually, thats working, and i can see that in the LOG window is sayes "Main.Event"
When I do a eg.EventTrigger('Event') I can see in the LOG windows "Main.Event" but nothing happens...

whats the trix?


I have a macro and i have a event...


Eddie
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: if or else or goto or break or label...

Post by krambriw »

Put a picture here of your macro configuration
eddiex666
Posts: 41
Joined: Fri Sep 12, 2014 10:34 pm

Re: if or else or goto or break or label...

Post by eddiex666 »

loop:

Whatever i try, the IF is not working...
here is my script:

Code: Select all

mintemp = ('10')
temp2 = ('15')

def doTurnOn():
    print "False, Det er kaldere en "+ mintemp + " grader inne"

def doTurnOff():
    print "True, det er varmere en "+ mintemp + " grader inne"

if float(temp2)<(mintemp):
    doTurnOff()
elif float(temp2)>(mintemp):
    doTurnOn()
print 'End'
if "mintemp" is lower, its do a turn on.... as it should...
if "mintemp" is higher, its do a turn ON ....

Syntax error?
eddiex666
Posts: 41
Joined: Fri Sep 12, 2014 10:34 pm

Re: if or else or goto or break or label...

Post by eddiex666 »

attached a screendump... witch showa the script LOG , and al my macro, events...
Attachments
EG Screendump
EG Screendump
eddiex666
Posts: 41
Joined: Fri Sep 12, 2014 10:34 pm

Re: if or else or goto or break or label...

Post by eddiex666 »

Hi K....

I got the script to work on the if statment...
I know you recomend me alot of thing... i just have to say... I am old and stabish :-)

My only problem now, is how to "call / start" a event from the script...

eg.TriggerEvent('Turnon') does not work ... syntax?


Tnx for all gooood help ...


Eddie
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: if or else or goto or break or label...

Post by krambriw »

eg.TriggerEvent('Turnon') does not work ... syntax?
Of course it does but you have selected not to view unassigned events...
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: if or else or goto or break or label...

Post by krambriw »

You have to use the same data types when comparing the values....

Code: Select all

#mintemp = ('10')
#temp2 = ('15')


def doTurnOn():
    print "False, Det er kaldere en "+ mintemp + " grader inne"

def doTurnOff():
    print "True, det er varmere en "+ mintemp + " grader inne"


mintemp  = raw_input("Mintemp ?")
temp2 = raw_input("temp2 ?")

if float(temp2)<float(mintemp):
    doTurnOff()
elif float(temp2)>float(mintemp):
    doTurnOn()
print 'End'

eddiex666
Posts: 41
Joined: Fri Sep 12, 2014 10:34 pm

Re: if or else or goto or break or label...

Post by eddiex666 »

Hi,

ok I found the way...

seems that i did not get the eg.TriggerEvent to work....

but when i right clicked on a event and selected "copy as python" i got the correct syntax...
this is working for me..

Code: Select all

def doTurnOn():
    print "False, Det er varmere en "+ mintemp + " grader inne"
    eg.plugins.TellStickDuo.TurnOff(9)
so the e.plugins.TellstickDuo.TurnOff(9) is working nice..


Tnx K....


Eddie
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: if or else or goto or break or label...

Post by krambriw »

Eddie, you can't fly before you have your wings...

Code: Select all

eg.plugins.TellStickDuo.TurnOff(9)
is something completly different to

Code: Select all

eg.TriggerEvent('Turnon') 
You have to spend a lot more time reading and experimenting (by yourself). It makes no sense that you scatter the board with all of your working or non working tests.

Think carefully about what you want to ask AND try to make it as illustrative as possible with screenshots etc so that is clear what you want.

Is not that you should not ask but since you are new, we do expect that you spend a lot in self studying. There are many threads and samples that will help you get going.

Best regards, Walter
Post Reply