Forum Discussion
Help needed with seemingly simple logic
Hi all,
I'm trying to figure out how to change a button state when you click on it, then change it back to the original state when you click it again. It seems simple, but it just won't work for me, and I'm hoping someone here will tell me where I'm going wrong. I've included the file with this post.
All I want is to when I click on the button (starts off in the "Off" state) to change to a new state (ie "On" state), but then when I click it again, it switched back to the original state (ie the "Off" state).
Currently, I can get it to change once to the "On" state, but it won't change back to the "Off" state when I click it again. I've added a tracking T/F variable called "buttonOn" as a way of controlling the state of the button. The button (called OnOff Button) has two states: Normal and buttonOn)
Here are the triggers I've got in the order they appear:
1) Set buttonOn to value True
When the state of OnOff Button is buttonIsOn
2) Set buttonOn to value False
When the state of OnOff Button is Normal
3) Set state of OnOff Button to Normal -----> (ie State 1)
When the user clicks OnOff Button
If buttonOn = value True
(ie change the button to be Off when the user clicks the button and visual state of the button is On)
4) Set state of OnOff Button to buttonIsOn ----> (ie State 2)
When the user clicks OnOff Button
If buttonOn = value False
(ie change the button to be On when the user clicks the button and the visual state of the button is Off)
Seems logical to me, but it doesn't work. I can get it to change once, but it won't change back to the original state. I can do it using layers, but I'd rather stick with changing states.
What am I doing wrong?
i've noticed that when I try editing the different states, there are triggers that appear where I can't delete them. Is this normal?
Hi Doug, I saw your comment about your posts being reported right away. Not sure what is causing that but I'll look into it.
For your button, a quick fix is to switch your buttonison state to the built-in selected state. With the selected state, you don't need triggers for it to work, and you can still have variables that track the button state if you need that. I've attached an example. Hope this helps. Please let me know if you have any questions!- DougArnold-26e1Community Member
Yup, that definitely fixed the problem. Thanks, Ginger ! :-)
- AngeCommunity Member
Hi Doug check out this tutorial:
Look slike you have overcomplicated the process for a simple on/off switch.
https://www.youtube.com/watch?v=C0lFFG4AlLE
I tried adding the edited SL but for some reason I received an error.
I hope the video helps.- DougArnold-26e1Community Member
Me? Over-complicate things? Never ! lol
Yup, over-complicating things was definitely the root cause of the issue. I've looked at other people's responses (fixed states) as well and fixed the problem, but I'll definitely have a look at the YT video as well.
Thanks for your help! :-)
Edit: Just looked at the YT video. Even after using SL for about nine years, I learnt something new from it (re: Toggle vs Set) today ! :-)
- JudyNolletSuper Hero
FYI: You can save yourself from a lot of headaches by taking advantage of built-in state. Here's more info: https://community.articulate.com/discussions/articulate-storyline/primer-take-advantage-of-built-in-states
- JudyNolletSuper Hero
By the way, posting the same question in multiple areas and/or multiple times might seem like a good way to get noticed.
For example, you posted this question in both the Building Better Courses and the Storyline area.
- https://community.articulate.com/discussions/building-better-courses/help-needed-with-seemingly-simple-logic
- https://community.articulate.com/discussions/articulate-storyline/help-with-seemingly-simple-button-logic
- https://community.articulate.com/discussions/articulate-storyline/help-with-seemingly-simple-button-logic-eb3fb514-4cea-439c-bc0d-469d519fbc38
I'm assuming that the 2 posts in the Storyline area are due to the issues you had with your posts being auto-reported.
Duplicating posts complicates getting a good answer, since different folks might reply to different posts (as with this post). That also makes it harder for someone else who's searching for the answer to the same or a similar question.