How do I remove value from a var when I stop overlapping obj

Get help using Construct 2

Post » Mon Oct 10, 2016 1:30 pm

Hey guys.

So this one is confusing me quite a bit. I want to add value to a var of an object when another instance of an object is overlapping it (one of many that could and would at the same time) then remove the same value when this instance of the object is no longer overlapping it.

Example:

Object 1 has var which fills when ever an instance of Object 2 overlaps it, by the amount which is custom for every instance of Object 2. Take for example there are two Object 2s, one has a var with a value 20, the other 30. The Object 1 var value would become 50 when both Object 2 instances overlap it, but when one of them stops overlapping, the value would drop to 20 or 30, depending on which instance stops overlapping....am i making any sence?

Any help on this would be hugely appreciated.
Thanks!
B
18
S
3
Posts: 65
Reputation: 994

Post » Mon Oct 10, 2016 1:43 pm

https://www.dropbox.com/s/rj7kegisfsm3yiv/test.capx?dl=0

Ok, so here is a quick capx illustrating the issue. It is a bit different than my original explanation, but basically it comes to the same thig.
One event gives 20 when on of the two green squares overlaps the blue one, and the other gives 300. You have contorl over the one that gives 300. WHen you overlap the blue object, the text object will display the value that you add to. Now, what I need is a way to remove from the value the moment the controlable green square stops overlapping with the blue one.

Any ideas?
B
18
S
3
Posts: 65
Reputation: 994

Post » Mon Oct 10, 2016 3:13 pm

Hey man,

I see what you're up to.
I modified your capx and corrected your initial event sheet.
I also added another event sheet, called "Improved" which includes a function. Functions make your life way easier and this event sheet is also more compact than your initial one. I added several comments, I hope I can help you. :)
(Switch between the Event Sheets by clicking your Layout and then choosing the Event Sheet on the left)

If you have questions, don't hesitate to ask.

Download: https://www.dropbox.com/s/yvefkfwpm5mnk25/test.capx?dl=1

Btw, you can add as many instances of Sprite2 and change their values to whatever you prefer, my improved version will still work. ;)
(I changed the movement, you now control the Blue Sprite via Drag & Drop)
Last edited by randomly on Sat Oct 15, 2016 7:47 am, edited 1 time in total.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Oct 10, 2016 3:49 pm

Hey man, thanks a million!
This is really great and I got the idea - nice and simple. Great explanation, thanks again.
Very helpful, exactly what I needed.

Hope I can start being of help around this forum as well, still have a ways to go though :).
Thanks again.
B
18
S
3
Posts: 65
Reputation: 994


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 29 guests