Forum Discussion

JohnJohnson-6a8's avatar
JohnJohnson-6a8
Community Member
3 hours ago
Solved

2-condition trigger issue

I am trying to get very good with triggers, variables and conditions. I have a slide with variables - the metaphor is cooking. I want a fire extinguisher icon to appear when 2 conditions are true: Timer set for 120 minutes AND temperature set for 450 degrees. 

When I preview, it basically works, but I don't like how the trigger seems dependent on the timer slider. I've attached the file. Wondering whether I approached this trigger incorrectly.

Thank you for any clues.

  • Have a look at the attached and see if that's what you wanted. I added a True/False variable that is toggled every time either the slider or dial is moved. The status of the fire extinguisher is changed every time this T/F variable changes (rather than the timer slider variable) IF the correct temperature and time is set. 

6 Replies

  • What an education! Thank you for responding...your logic makes sense and clearly there is more than one way to do this. I appreciate you showing me a few of them.

  • DShaw's avatar
    DShaw
    Community Member

    Here’s another solution just to show you there are often several ways to work with triggers, conditions and variables to achieve your goal. Your conditions were fine, the problem is the event. The trigger reads, change state of fire extinguisher to normal when timer changes, if timer == 120 AND temperature == 450 (else Hidden). SL only evaluates conditions at the instant the event fires, nothing continuously watches variables. So if the slider’s already at 120 and you then dial the temperature to 450, no event fires and the extinguisher stays hidden. Same on the way out, drop the temperature and it stays visible until the timer moves. That’s the timer-dependence you were seeing. The standard pattern for AND conditions across two variables is one trigger per variable, identical conditions on each.

    • CarlFink1's avatar
      CarlFink1
      Community Member

      I haven't looked at the .story file, but in general I'd use >= and not == for those comparisons. Might work perfectly here, but in general it introduces the possibility that temp goes up to 500 ... and the fire extinguisher never appears, because 450==500 evaluates as false.

  • Nedim's avatar
    Nedim
    Community Member

    It won't work if you set the Timer to 120 first and then set the Temperature to 450 degrees, because the fire extinguisher's state is evaluated only when the Timer variable changes, not when the Temperature variable changes.

    To resolve this, add an additional trigger that changes the fire extinguisher's state to Normal when the Temperature (dial) changes, using the same conditions. This ensures the state is evaluated whenever either variable changes, regardless of the order in which the user adjusts them.

    Current trigger:







    Additional trigger:

    If you're a fan of JavaScript, you can implement this interaction with a single trigger. Simply add an Execute JavaScript trigger that runs when the timeline starts:

    const fireextinguisher = document.querySelector('[data-model-id="6mukAbVtlHP"]');
    
    setInterval(() => {
        const timer = getVar('Timer');
        const temperature = getVar('temperature');
    
        if (temperature === 450 && timer === 120) {
            fireextinguisher.classList.remove('hidden');
        } else {
            fireextinguisher.classList.add('hidden');
        }
    }, 100);

    Both implementations are included in the attached Storyline project file.

  • that is a far better approach than the one I'd tried. I like that you introduced another T/F variable as another connector TO  temp and time values.

    Very elegant method. Thank you!

  • MichaelHinze's avatar
    MichaelHinze
    Community Member

    Have a look at the attached and see if that's what you wanted. I added a True/False variable that is toggled every time either the slider or dial is moved. The status of the fire extinguisher is changed every time this T/F variable changes (rather than the timer slider variable) IF the correct temperature and time is set.