Quick question about toggle buttons

Get help using Construct 2

Post » Sat Aug 09, 2014 12:32 pm

@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.
B
6
Posts: 30
Reputation: 292

Post » Sat Aug 09, 2014 2:05 pm

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.
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sat Aug 09, 2014 4:45 pm

@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) :lol: 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)
B
6
Posts: 30
Reputation: 292

Post » Sat Aug 09, 2014 9:58 pm

discoverthecurse wrote:@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) :lol: 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 have option_text_1=0, option_text_2=1, option_text_3=2 (or similar) instead of on_text/off_text. Will you be having more than that? :geek: 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.
Last edited by codah on Sun Aug 10, 2014 1:16 pm, edited 2 times in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sun Aug 10, 2014 12:03 pm

No there is only gonna be the 3 difficulties. Can you explain the wrap around operation?
B
6
Posts: 30
Reputation: 292

Post » Sun Aug 10, 2014 1:15 pm

Global constant number NBR_OF_DIFFICULTIES = 3
btntxt: Set self.my_state to (self.my_state + 1) % NBR_OF_DIFFICULTIES
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sun Aug 10, 2014 4:37 pm

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?
B
6
Posts: 30
Reputation: 292

Post » Mon Aug 11, 2014 7:51 am

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).
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Aug 11, 2014 8:22 pm

Alright cool cool. Ill have to give that a try and see what happens, thanks!
B
6
Posts: 30
Reputation: 292

Post » Thu Aug 14, 2014 2:46 am

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

Image
B
6
Posts: 30
Reputation: 292

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests