Forum Discussion

CarlFink1's avatar
CarlFink1
Community Member
14 hours ago

Detect all click or all keyboard events for trigger

So here's what I mean: I have a slide where the user must interact with all three buttons before progressing. I start with Next disabled, and a variable increases each time one is clicked. When the count reaches 3, Next is disabled.

But that requires each button to have a separate trigger that checks the count and potentially changes the state of Next.

What I used to do in software like Asymetrix Toolbook was have the page (they used a book metaphor) also receive mouse/keyboard events, so there could be a single code block on the page to activate the Next button when the count reached 3.

Any special reason a slide couldn't receive events from all objects it encompasses? Sure, 95% or more of the time it would ignore them, but sometimes that's really useful.

Just add "Anywhere on this slide" (and maybe "Anywhere on this layer") to the list shown below.

 

5 Replies

  • CarlFink1​: Here's the set up of your slide: "I have a slide where the user must interact with all three buttons before progressing. I start with Next disabled, and a variable increases each time one is clicked. When the count reaches 3, Next is [en]abled."

    Unless you're also disabling each button when it is clicked or adding extra triggers like Andrew mentioned, counting clicks isn't a good option. For example, if a user clicks the same button 3 times, the count = 3. 

    Based on the description, I don't think you need any variables. Instead, give each button a Visited state, and use that to control Next. 

    • A button with a Visited state automatically changes to Visited when clicked. But that state can just be a duplicate of Normal if you don't want a visible change.

     

    If the user remains on the slide after clicking a button, enable Next when all the buttons are Visited. That trigger would look something like this: 

    If the user jumps to another slide when they click a button, use a trigger that changes the state of the Next button to Normal when the timeline starts on the slide, with conditions that each button = Visited. (That could have an else statement that disables Next, so you only need one trigger to disable/enable.)

    • Note: A “when timeline starts” triggers runs every time the user reaches the slide—even if the Slide Properties are set to “Resume saved state.” That's why that type of trigger often needs one or more conditions. 
  • CarlFink1's avatar
    CarlFink1
    Community Member

    I see now that I could use "When variable changes" for this specific case ... and I will. I like the idea in general, though.

    • AndrewBlemings-'s avatar
      AndrewBlemings-
      Community Member

      The non-code option when I need functionality like this is to give each button a trigger that updates a button-specific boolean (e.g., button1Clicked, button2Clicked, and button3Clicked) to true.

      Then some subsequent triggers can increment a numeric variable (e.g., buttonsClicked) when button1Clicked changes if button1Clicked = true. This prevents the behavior of someone clicking one button three times and incrementing the buttonsClicked variable three times. Instead, the boolean flips once, and since that button1 boolean never flips again, the trigger that increments the count can only fire once per button.

      If you're open to JavaScript, a general document-level event listener can capture the mouse click.

      document.addEventListener('pointerdown', (event) => {
      
      	let newCount = (getVar('timesClicked') + 1);
      	setVar('timesClicked', newCount);
      	
      });

      The API also describes an object-level event handler. Each object could be given one function to run, and that one function could handle the increment.

      • CarlFink1's avatar
        CarlFink1
        Community Member

        Thanks. What you describe above is precisely what I did implement after starting this thread, but before checking back.😂

        I'm open to JS, but also not very familiar with it. (I hate c-like languages, so I have a mental block about learning it, but that isn't a reflection on anything but my own weird background as a former FORTRAN developer.)