Forum Discussion
Help with seemingly simple button logic
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?
- MichaelHinzeCommunity Member
To toggle a button, you can simply use the built-in Normal and Selected states, no triggers needed. These states are called automatically when a button is clicked/unclicked. See the sample button I added on slide 1.1.
- DougArnold-26e1Community Member
Hi Michael,
thanks for your reply. I haven't looked at your .story file yet, but I've seen other responses similar to yours. I tried it, and it works, yet I don't understand why. I think the root cause of the issue was simply me trying to over-complicate things! lol.
thanks again for your help
- JudyNolletSuper Hero
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.