Add values to variables through the two images interaction

0 favourites
  • 8 posts
From the Asset Store
Kids Game
$49 USD
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • 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).

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

  • Thanks. Can I use this method with instances of the same sprite? I'm using a variable (order) to control each instance.

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

  • Oh my gosh! It's greek for me

    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?

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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?

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

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