I feel stupid for asking, but I canÔÇÖt figure out how to do something, even after reading multiple threads with a similar topic. How do you conditionally execute a macro based on the value of a variable? I have IR controlled theater curtains that IÔÇÖve written macros for that change their position (e.g. ÔÇ£Closed to 1.78ÔÇØ, ÔÇ£1.85 to OpenÔÇØ, etc.). So I set the value of the variable ÔÇÿPositionÔÇÖ as 0 (Closed), 1.78, 1.85, or 2.35 (Open). I would like for EG to decide which macro to use to change the curtain position rather than relying on the user. In a generic language, it would be something like:
Trigger for 1.78
If Position = 0 then Call Macro(ÔÇ£0 to 1.78ÔÇØ)
Elseif Position = 1.78 then Do Nothing
Elseif Position = 1.85 then Call Macro(ÔÇ£1.85 to 1.78ÔÇØ)
Elseif Position = 2.35 then Call Macro(ÔÇ£2.35 to 1.78ÔÇØ)
Any help out there? Thanks very much.
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 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.
Execute a macro based on the value of a variable?
Re: Execute a macro based on the value of a variable?
I think I'm starting to catch on a little from this thread: viewtopic.php?f=2&t=2163&p=12360&hilit= ... nal#p12360
Still many things I don't understand. What is the meaning of this syntax: "if mystate: eg.result = True"? Why isn't it just "if mystate = True"?
The biggest stumbling block to my understanding is the EG Jump command. What does "if last action was successful" mean? In this example, how is "if mystate: eg.result = True" successful or unsuccessful? I would think that "last action was successful" means that the command executed, and it would whether mystate was true or false.
Still many things I don't understand. What is the meaning of this syntax: "if mystate: eg.result = True"? Why isn't it just "if mystate = True"?
The biggest stumbling block to my understanding is the EG Jump command. What does "if last action was successful" mean? In this example, how is "if mystate: eg.result = True" successful or unsuccessful? I would think that "last action was successful" means that the command executed, and it would whether mystate was true or false.
Re: Execute a macro based on the value of a variable?
I think I finally found the answer to my own question here: http://www.eventghost.net/docs/scriptin ... light=jump
eg.result
Every action in EventGhost returns a result. For most actions this is simply PythonÔÇÖs None, but some might return a result that is useful for later evaluation. For example the ÔÇÿWindow/Find WindowÔÇÖ action returns a list of the window-handles it has found (or an empty list if it hasnÔÇÖt found anything). So you can place a PythonScript directly after the ÔÇÿFind WindowÔÇÖ action and do something with this list.
The ÔÇÿEventGhost/JumpÔÇÖ action also uses eg.result as the condition to decide what it has to do. If eg.result is determined as True by PythonÔÇÖs standard truth testing procedure, the ÔÇÿJumpÔÇÖ action will regard the result of the last action as ÔÇÿsuccessfulÔÇÖ and do a jump if configured so. So you can use this circumstance to control a ÔÇÿJumpÔÇÖ from a PythonCommand or PythonScript, by assigning something to eg.result. For a PythonCommand you actually donÔÇÖt need to assign directly to eg.result, because the result of a Python evaluation is automatically assigned to eg.result. If you make a PythonCommand like ÔÇÿmyVar == 1ÔÇÖ, EventGhost will compute this to True if ÔÇÿmyVarÔÇÖ is 1 or to False if ÔÇÿmyVarÔÇÖ is anything other and assign this True/False result to eg.result.
Re: Execute a macro based on the value of a variable?
I figured it out. A Python command like "CurrentPos == 2.35" with two equal signs does not set the value of CurrentPos, but compares the two values. If CurrentPos equals 2.35, then a True result will be returned, otherwise a False result will return. The EG Jump command option of "If successful" is considered "successful" if the previous command returned a True value. So, I've tested the following example and it works great.
- jitterjames
- Experienced User
- Posts: 677
- Joined: Thu Aug 13, 2009 4:36 pm
- Location: Quebec, Canada
- Contact:
Re: Execute a macro based on the value of a variable?
sometimes "thinking out loud" is the solution 
