How do I Add different values using same buttons?

Get help using Construct 2

Post » Thu Oct 29, 2015 3:02 am

So in the capx example, I have 2 sprite buttons. BUT, they are copy/pasted.

How would I add 1 to the variable "points" by clicking the left (+1) button and add 2 by clicking on the right (+2) button. As far as the events go, both buttons register as +1 clicks.

Thanks in advance.

capx:
drive.google.com/file/d/0BzM_Ir0LBMx_Q01rQ1ZrRGNzT0E/view?usp=sharing
B
6
Posts: 40
Reputation: 336

Post » Thu Oct 29, 2015 3:44 am

I haven't looked at your capx but if the two buttons are instances of the same type, then you could give them an instance variable, call it value and set one to 1 and the other 2. Finally when you click on it add button.value.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Thu Oct 29, 2015 8:19 pm

R0J0hound wrote:I haven't looked at your capx but if the two buttons are instances of the same type, then you could give them an instance variable, call it value and set one to 1 and the other 2. Finally when you click on it add button.value.

How do I set one to "1" and the other to "2", when they are the same sprite/has the same instance variables?

BTW here's the print screen of the 2 sprite buttons. They are copy/pasted (as shown by only 1 sprite object in the project bar).

Image
B
6
Posts: 40
Reputation: 336

Post » Thu Oct 29, 2015 8:53 pm

Different instances can have a different values for an instance variable (the variable name is ofcourse the same)..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Oct 29, 2015 10:39 pm

LittleStain wrote:Different instances can have a different values for an instance variable (the variable name is ofcourse the same)..

I do not get how to set this up in the events. Both sprites still add the same amount when clicked.

EDIT: Never mind, just got it :D
Thanks
@R0J0hound
@LittleStain
B
6
Posts: 40
Reputation: 336

Post » Thu Oct 29, 2015 10:49 pm

In editor click on "+1" sprite and set the instance variable (eg value) to 1
In editor click on "+2" sprite and set the instance variable (value) to 2

In event sheet:
On left click on "sprite" : -> system add sprite.value
Image Image
B
25
S
14
G
139
Posts: 876
Reputation: 72,510

Post » Thu Oct 29, 2015 11:09 pm

MadSpy wrote:In editor click on "+1" sprite and set the instance variable (eg value) to 1
In editor click on "+2" sprite and set the instance variable (value) to 2

In event sheet:
On left click on "sprite" : -> system add sprite.value

Already sorted it, but thanks though. Good for future reference.
B
6
Posts: 40
Reputation: 336


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 22 guests