Add values to variables through the two images interaction

Just started using Construct 2? Post your questions here

Post » Tue Oct 18, 2016 12:00 pm

I need to add a value in two variables when the user interacts with two images. The user must click on the first image to add the value of the first variable and, without releasing the mouse button, go to the second image, then release the mouse button (this is not drag 'n drop) to add the value in the second variable . Is it possible? (I hope so).
B
4
S
2
Posts: 129
Reputation: 858

Post » Tue Oct 18, 2016 2:05 pm

Here is a capx of what you described.
https://drive.google.com/open?id=0Bx-ufu2WID53X2ZxQThQeGIxME0 Click the download icon in upper right corner.

It was pretty easy with the CS2 mouse object commands, didn't have to use any trickery.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
68
S
17
G
8
Posts: 637
Reputation: 9,420

Post » Tue Oct 18, 2016 2:23 pm

Thanks. Can I use this method with instances of the same sprite? I'm using a variable (order) to control each instance.
B
4
S
2
Posts: 129
Reputation: 858

Post » Tue Oct 18, 2016 4:31 pm

I would think you could, definitely not as easily. You would need to store the UID or IID (more here on them: https://www.scirra.com/tutorials/361/understanding-uid-iid-health-cards-and-rocket-smoke-trail of the first instance you click into a variable and then condition out that it is different than the second instance when button released. This is as simple as grabbing the first instance UID/IID with an action in its event that stores the value in a variable. Then in the event for the release of click grab the UID/IID of the object under cursor and condition out that is does-not-equal original stored UID/IID.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
68
S
17
G
8
Posts: 637
Reputation: 9,420

Post » Tue Oct 18, 2016 6:53 pm

Oh my gosh! It's greek for me :o

I thought that it would be easy. I always use a variable in the sprite and I only work with instances. My game is almost ready and I would like to keep the instances. Is there another way to solve it? Please?
B
4
S
2
Posts: 129
Reputation: 858

Post » Tue Oct 18, 2016 7:36 pm

Did you try this?

Global Variable1 = -1
Global Variable2 = -1

Mouse Button is down
-Cursor is over image & Image is "active/ready" (make an instance boolean)
--Variable1 = -1 -> variable1 = image.instancevariable & set image boolean to false
--else Variable2 = -1 -> Variable2 = image.instancevariable & set image boolean to false

On button released
-Variable1 =! -1 && Variable2 =! -1 then [where ever you need the sum to go] = Variable1 + Variable2 (& set Variable1 & 2 back to -1)
ImageImageImage
B
40
S
23
G
11
Posts: 498
Reputation: 10,062

Post » Wed Oct 19, 2016 11:01 am

badmoodtaylor wrote:Did you try this?

Global Variable1 = -1
Global Variable2 = -1

Mouse Button is down
-Cursor is over image & Image is "active/ready" (make an instance boolean)
--Variable1 = -1 -> variable1 = image.instancevariable & set image boolean to false
--else Variable2 = -1 -> Variable2 = image.instancevariable & set image boolean to false

On button released
-Variable1 =! -1 && Variable2 =! -1 then [where ever you need the sum to go] = Variable1 + Variable2 (& set Variable1 & 2 back to -1)



I need to use the touch object and I will have more than 2 images (6 or 10 in total) by always clicking on two at a time. Can I use the same script with touch and with more instances than 2?
B
4
S
2
Posts: 129
Reputation: 858

Post » Wed Oct 19, 2016 2:17 pm

Braus wrote:I need to use the touch object and I will have more than 2 images (6 or 10 in total) by always clicking on two at a time. Can I use the same script with touch and with more instances than 2?


You can do the same thing with touch instead of mouse.

You should be able to adapt this to different conditions. If you are adding up a varied amount of numbers I would just make a global variable and add the instance variable to the global variable.

I'm not really sure what you are asking or what your scenario is specifically, but I would rather you ask questions based on understanding rather than tailoring to your scenario. If you don't understand I may be able to make a capx example tomorrow to show you but I won't write your code for you.
ImageImageImage
B
40
S
23
G
11
Posts: 498
Reputation: 10,062


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests