Odd Script Behavior

Posted on
Mon Jun 10, 2013 4:03 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Odd Script Behavior

Hey,

I have an AS that executes fine if all 4 TVGlow variables are true, or if the 1st 2nd and 3rd are true, or even the first 2.
It will not work if just TV2Glow, TV3Glow or TV4Glow are true individually.

Any idea what I'm missing here?

Code: Select all
tell application "IndigoServer"
   if the value of variable "TV1Glow" is "true" then
      execute group "TV VolUp"
      if the value of variable "TV2Glow" is "true" then
         execute group "TV VolUp"
         if the value of variable "TV3Glow" is "true" then
            execute group "TV VolUp"
            if the value of variable "TV4Glow" is "true" then
               execute group "TV VolUp"
            end if
         end if
      end if
   end if
end tell


Thanks for any help!

Carl

Posted on
Mon Jun 10, 2013 5:08 pm
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Odd Script Behavior

That's because your scripts logic doesn't say "if any of these variables is true". Fundamentally what it really says is if TV1Glow is true then turn the volume up and then if TV2Glow is true turn it up more and then if TV3Glow is true then turn it up even more and then if TV4Glow is true then crank it one more time. If they're all true, the action group gets executed 4 times.

What you want to say is if TV1Glow or TV2Glow or TV3Glow or TV4Glow is true then execute the group.

AppleScript:

Code: Select all
tell application "IndigoServer_d"
   if (value of variable "TV1Glow" is "true") ¬
      or (value of variable "TV2Glow" is "true") ¬
      or (value of variable "TV3Glow" is "true") ¬
      or (value of variable "TV4Glow" is "true") then
      execute group "TV VolUp"
   end if
end tell


Python:

Code: Select all
tv1 = indigo.variables["TV1Glow"].getValue(bool, default=False)
tv2 = indigo.variables["TV2Glow"].getValue(bool, default=False)
tv3 = indigo.variables["TV3Glow"].getValue(bool, default=False)
tv4 = indigo.variables["TV4Glow"].getValue(bool, default=False)
if tv1 or tv2 or tv3 or tv4:
    indigo.actionGroup.execute(GROUPID)


Of course, you really should use the ID of the variable not the name so if you change it the script won't break.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jun 10, 2013 5:28 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Odd Script Behavior

Sorry, wasn't sure it mattered but in my example script I didn't include that the TV Volumes are all different depending on which glow is true.

Code: Select all
tell application "IndigoServer"
   if the value of variable "TV1Glow" is "true" then
      execute group "TV1 VolUp"
      if the value of variable "TV2Glow" is "true" then
         execute group "TV2 VolUp"
         if the value of variable "TV3Glow" is "true" then
            execute group "TV3 VolUp"
            if the value of variable "TV4Glow" is "true" then
               execute group "TV4 VolUp"
            end if
         end if
      end if
   end if
end tell


Same issue I suppose, in that no if statement will process past any that aren't true.
Been trying a number of "or" statements but still no go.

Edit: Just tried putting them all in tell blocks and it seems to work fine.

Many thanks,

Carl

Posted on
Mon Jun 10, 2013 5:44 pm
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Odd Script Behavior

In that case, just one if/then for each one - not embedded.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jun 10, 2013 7:23 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Odd Script Behavior

Gotcha, thanks again.

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests