Jump to content

If statement help


beninsteon

Recommended Posts

Posted

Hi,

Hoping someone can help me how to figure this out.

I want to run program X if variable Y goes from 0 to 1, but not if it goes from 2 to 1. Thus, I can't use the if statement "if Y is 1 then"....because this will execute regardless of Y's previous value (0 or 2).

In practical terms, when sMusic is 0 it means the speakers are off, when it's 1 music is playing, and when it's 2 music is paused.

When the system turns on I want certain things to run (eg. turn amp on, set proper input, etc). I don't want these actions to occur when music goes from pause to play.

Any suggestions?

Thanks!

Posted
2 minutes ago, beninsteon said:

Hi,

Hoping someone can help me how to figure this out.

I want to run program X if variable Y goes from 0 to 1, but not if it goes from 2 to 1. Thus, I can't use the if statement "if Y is 1 then"....because this will execute regardless of Y's previous value (0 or 2).

In practical terms, when sMusic is 0 it means the speakers are off, when it's 1 music is playing, and when it's 2 music is paused.

When the system turns on I want certain things to run (eg. turn amp on, set proper input, etc). I don't want these actions to occur when music goes from pause to play.

Any suggestions?

Thanks!

What are you using to turn your amp on or change inputs? Depending on setup, even if you run those same things again, it may not effect anything and start up the way you like 

I'm regards to actually program, you could make 2 folders and drop your programs in. 1 folder will only run if the variable is at 0, the other if the variable is set to 2. Put what you want in the corresponding folder

  • Thanks 1
Posted
14 hours ago, beninsteon said:

Hi,

Hoping someone can help me how to figure this out.

I want to run program X if variable Y goes from 0 to 1, but not if it goes from 2 to 1. Thus, I can't use the if statement "if Y is 1 then"....because this will execute regardless of Y's previous value (0 or 2).

In practical terms, when sMusic is 0 it means the speakers are off, when it's 1 music is playing, and when it's 2 music is paused.

When the system turns on I want certain things to run (eg. turn amp on, set proper input, etc). I don't want these actions to occur when music goes from pause to play.

Any suggestions?

Thanks!

 

This is reasonably easy to do, but you need a second variable.  and for that variable a simple integer variable will do.  Since the state variable is sMusic, let's call this one iMusic.

Program 1

If

    sMusic = 1

then

    (do whatever need to always be done)

    Run Program 2 (if)

else

    (none)

 

Program 2 (DISABLED)

if

    iMusic = 0

then

    (do whatever needs to happen if the old setting was 0

    iMusic = sMusic

else

    Run Program 3 (if)

 

Program 3 (DISABLED)

If

    iMusic = 2

then

    (do whatever needs to happen if the old setting was 2

    iMusic = sMusic

else

    iMusic = sMusic   /* keeps variables in sync if old was neither 1 or 2

 

The key element here is that Programs 2 and 3 are disabled, which means they will not run automatically when the IF statement becomes true.  In actuality in this case since the IF statement is only using a integer variable it wouldn't anyway, but if the variable was a state variable or some other object that could become true, if the program is disabled it won't run by itself, but will run if linked from another program.

Obviously you have to have the variables in synch to start with, but they should stay that way with this program series.

 

  • Like 1
Posted

Condensing @MrBill's concept, you should be able to do this in one program. Trouble is $iMusic may need to be initialised at power up. With the variable iMusic init to to 0, the initialisation should not be required. By default, the iMusic will be set to 0 without any initialisation. This only works for 0.
This will detect 0 to 1 only. AnyOtherValue to 1 will not run whatever process.

Program Detect 1 to 0 [enabled]

If
      $sMusic = 1
    AND
      $iMusic = 0 <---------- check old value
Then
      do whatever
      $iMusic = $sMusic <------------ keep last value for change detection
Else
      $iMusic = $sMusic <------------ keep last value for change detection
   

  • Like 2
Guest
This topic is now closed to further replies.

×
×
  • Create New...