Forum Discussion

CaitlinGraham's avatar
CaitlinGraham
Community Member
8 months ago

Help creating a bar which counts found objects using variables/states

Hi folks,

I'm new to Storyline, so I apologize if this seems obvious, but I feel like I've tried everything and am at my wit's end. I'm trying to create a game where you have to click on all of the HOA violations you see in a single slide. As you click on each one, a little bar on the left rises and the counter goes up. The problem is, I want the user to be able to click on them in any order. 

I tried using variables to make this work where if you clicked on an object, theoretically it would add +1 to the value and trigger a state change on the bar graphic. But it will only work if I give a specific value to each object, and then that doesn't allow users to select them out of sequence. Am I missing something? I'm going to try to attach my project here for reference. 

Thanks in advance.

  • I do think its quite easy to solve. Now you have a trigger on your questions like this.
    'Set hoaObjects to 1'... and the same on all questions... thus it will be set to 1 always.

    Change that to 'Add value 1 to hoaObjects'. Now the variable hoaObjects will increase (+1) when clicking more objects.

    Also i donot see any trigger affecting the bar.
    Best option is adding a trigger to the 'hoaObjects' variable. When that changes... change the state of the bar. Proper naming of elements in your view is important, as it makes it way easier to work with. Make a habit of that. I renamed 'rectangle4' to 'progressBar'.



    A quick test with 1 or 2 of the elements changed... and it works as expected.

    Good luck,
    Math

  • The danger of adding one to the count when an object is clicked, is that another one will be added if the same object is clicked again.

    It’s safer to count all the selected objects when one of them is selected. It works like this:

    Create a layer (Count) with nothing on it, that doesn’t hide other layers, and hides itself when its timeline ends. Set the timeline to .25 sec. Set all the triggers to fire when the timeline on the layer starts and put them in this order:

    Set hoaObjects to 0

    Add 1 to hoaObjects if state of Object1 =  Selected, etc. for each Object. (each object needs a selected state, but it doesn’t have to look different than Normal if your don’t need a visual indication of which ones are chosen.

    On the base, set these triggers: 

     Show layer Count when user clicks Object 1, etc for all objects.

    Then use Math’s trigger to change the progressBar.

    This way, a second click on an object deselects it. If you want a once-selected, always-selected action, use Visited state instead of Selected for the objects.

  • Ya'll are amazing -- thank you so much. I'm new to this and somehow I missed the add value command as a dropdown option. Such a stupid thing for me to miss. 

    And great tip about the clicking objects twice. I will use your method to fix that.