Quick question about toggle buttons

0 favourites
From the Asset Store
A challenging game that needs quick responses!
  • I want to set up a similar toggle button system like the one used in Minecraft for difficulties and such. I have a "buttontext" family set up for the text on the button and set it to the same size and position as the button itself. Then I set up the following event system:

    When I click the button it doesn't do anything. Is there an easier (working) way to do this or is there something I'm doing wrong?

    Thanks in advance,


  • Thats because condition one happens than condition to happens right after and both are valid.

    you can change the second condition to else (x on the keyboard) then if the first condition is true it will not check the second one and vis versa.

  • Really? I thought when it is set up like that it goes in line and checks to see which one is true at the time. What do you recommend? An "OR Block"?

  • Try replace the second condition with an 'else'.

  • It says that an "else is not valid there.

  • Read the manual more thorougly. Placing an else can be tricky at first.

    And, it's a lot easier to get help if you upload a capx.

    Edit: I might add, doing it this way (comparing text) is error prone. I would look at different ways of doing it, using a 'normal' numeric variable. Good luck.

  • Wouldn't using a boolean variable be much easier?

    on textbutton clicked - toggle variable On

    • if variable On is true - set text to "Bonus chest; On"
    • if variable On is false - set text to "Bonus chest; Off"

    You could also use a numeric variable

    on button clicked set variable: 1-variable

    that way you have the variable toggle between 1 and 0 too..

  • [attachment=0:3uii8eac][/attachment:3uii8eac]

    alright, this is the test capx i was experimenting these on. I have added 2 events so far to figure out how to get both of them going but as you can see when you click the difficulty one it changes the text to bonus chest. Ultimately what I am trying to do is have 2 buttons. A difficulty one that has 3 states (easy, normal, hard) and a bonus chest one that has 2 (on, off). I am obviously doing something wrong. I am probably going to change everything over to numeric variables but for some reason its only doing either button. not both.


  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Adding another button required a check on the 'else' to make sure which button we are dealing with. Then with the second button, just repeat what we did with the first. As you can see this method quickly gets cumbersome. There are some really good methods for handling buttons, you should search the tutorials.

    Edit: 2nd capx combines into one event.

  • I hate to be a pain but it isn't letting me open them because i don't have the beta release r176

  • Here. By the way there is a third party "toggle switch" behaviour which might be worth looking into. I haven't used it.

  • Download beta relase r176 here

    How you planning on storing this data?

    Here is attached a small demo I did a year ago - lol. Its very messy... but might help - shrugs

    Edit: Oh, wow, this demo was long ago - ha ha, anyways, if you touch the text at bottom it checks if shield is in the array... returns -1 if it isn't in array...meaning if the option is select/on then it returns numbers, else -1. I was playing around with various ways back then. The shield check is hard coded on line 7

  • Is this something that the "append text" feature might solve?

  • Is this something that the "append text" feature might solve?

    Yeah, you can do that. Just append it, or this is probably neater and more functional...

    Create an instance variable called state

    And set instance variable to either "On"or "Off"

    And set text to "Bonus Chest: " & state

  • With this you can add any number of buttons with no more code

    Edit: I didn't really explain how to use the capx very well. I've also simplified it--the family wasn't necessary.


    1. Copy the btntxt object to your project

    2. Copy the 1 event to your layout (no changes required)

    Then repeat these steps for each button you need:

    1. Drag a 'btntxt' onto your layout

    2. Set its text in the "my_text" instance variable (e.g. "Bonus Chest: ")

    3. Set its 'on' text in the "on_text" instance variable (e.g. "Normal")

    4. Set its 'off' text in the "off_text" instance variable (e.g. "Easy")

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)