Quick question about toggle buttons

  • > 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

    I tried this and I am getting an error message:

    According to Scirra's Expression page my syntax seems to be right but I isn't working. I don't know what I am doing wrong. Any suggestions?

  • discoverthecurse

    I'm assuming bcstate is an instance variable, in which case you with need to do ObjectType.bcstate instead as just bcstate by itself makes Construct 2 look for a global variable.

  • I have updated my above post with instructions for using the capx, if you're interested

  • I tried that and it let me click done but when I preview it changes it to "Bonus Chest:" and doesn't add the state. I am so lost.

    codah Im going to try implementing your system now. Thanks

  • codah I have tried instance variables, object variables and family variables and none of them will show up under the "toggle boolean" action dialog box. I don't get it. It keeps saying I need to add an instance variable first. I am beginning to think the copy of construct is damaged or something.

  • Just make them instance variables and make sure you choose the type 'boolean' for my_state. That message means you haven't done that. Copy the capx exactly I doubt your C2 is damaged.

  • codah Awesome thank you so much! that finally got it haha.

    Now.... I just need to know how to make a difficulty button with the same behavior that has 3 options (easy, normal, hard) any ideas?

    (and on a side note. is there an easier, more efficient way to simulate text shadow? i have just been using duplicate text objects with a different font color offset by a few pixels but it is becoming a little tedious to add double the events and objects and what not)

  • codah Awesome thank you so much! that finally got it haha.

    Now.... I just need to know how to make a difficulty button with the same behavior that has 3 options (easy, normal, hard) any ideas?

    )

    If you need to model 3 states, you will need a number variable instead of the boolean one (you should've said that's a requirement Then you will probably look into arrays..

    Then instead of Toggle Boolean you will have something like (pseudocode)

    btntxt:Set self.my_state to (self.my_state < 2 ? self.my_state + 1 : self.option_text_1)

    or you could use the % operator to 'wrap around' the values.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No there is only gonna be the 3 difficulties. Can you explain the wrap around operation?

  • Global constant number NBR_OF_DIFFICULTIES = 3

    btntxt: Set self.my_state to (self.my_state + 1) % NBR_OF_DIFFICULTIES

  • so its going to start out on 0, then you click and it goes to 1. then 2. and then if you click again it will see 3 and decide to go back to 0 right?

  • Yep. So first state (difficulty) is 0, second state is 1, third is 2. Starting at zero is kind of the convention in coding, because it's useful in lots of cases (like this one).

  • Alright cool cool. Ill have to give that a try and see what happens, thanks!

  • so i set everything up as far as i knew how to, then i got a syntax error right here

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