How do I implement while

Get help using Construct 2

Post » Sun May 15, 2016 3:45 pm

I have a cup and apple, when I place my apple on my cup I want the variable "onCup" to increase by 1, and when I remove it from the cup I want it to decrease by 1.
As I see it, there should be some listener that will listen to the condition, while its on the cup increase by 1, if its no longer on the cup then decrease by 1.
Didn't find any tutorial that explains this approach.

Something similar can be done with overlapping, but when I set current value of variable+1, it just goes razor fast up without limiting to the increment of 1.


Looking forward to your help.
B
11
S
3
Posts: 44
Reputation: 713

Post » Sun May 15, 2016 4:09 pm

Do you really need the variable then? The "Overlapping" condition is giving you the data you need.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Sun May 15, 2016 4:50 pm

StanBond wrote:Something similar can be done with overlapping, but when I set current value of variable+1, it just goes razor fast up without limiting to the increment of 1.


This is because it adds 1 every tick/frame while the apple is on the cup. I do not know if you just want it to be 1 for on cup, 0 if not on cup or if you want 1 to be subtracted/added every second. In the case of the latter, change add/subtract "1" to "1*dt", that will add one per second regardless of framerate.

You have three options if you just want 1 or 0 for on cup:

1) Instead of add to/subtract from variable use "set value" action.
2) Add a "trigger once while true" condition to the overlap event.
3) Don't use a global variable, add a boolean variable to the apple object called OnCup and set it to true/false if it is overlapping/not overlapping.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sun May 15, 2016 6:21 pm

blackhornet wrote:Do you really need the variable then? The "Overlapping" condition is giving you the data you need.


I have a button, which later on when I press got to check if the apple is on the cup


Pulstar wrote:
StanBond wrote:Something similar can be done with overlapping, but when I set current value of variable+1, it just goes razor fast up without limiting to the increment of 1.


This is because it adds 1 every tick/frame while the apple is on the cup. I do not know if you just want it to be 1 for on cup, 0 if not on cup or if you want 1 to be subtracted/added every second. In the case of the latter, change add/subtract "1" to "1*dt", that will add one per second regardless of framerate.

You have three options if you just want 1 or 0 for on cup:

1) Instead of add to/subtract from variable use "set value" action.
2) Add a "trigger once while true" condition to the overlap event.
3) Don't use a global variable, add a boolean variable to the apple object called OnCup and set it to true/false if it is overlapping/not overlapping.


Thanks I'll try this out
B
11
S
3
Posts: 44
Reputation: 713

Post » Sun May 15, 2016 6:25 pm

When you press the button, check if the apple overlaps the cup. No variable needed.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Sun May 15, 2016 8:04 pm

blackhornet wrote:When you press the button, check if the apple overlaps the cup. No variable needed.

I would do this but, I was looking for a solution that will allow me to have multiple cups.

For example, I have 3 cups - 2 of them red, and I have two apples, the apples must be placed on red cups only.
So at the end the user got the button to check if he placed them all correctly.
B
11
S
3
Posts: 44
Reputation: 713

Post » Sun May 15, 2016 10:45 pm

You can still detect this at button-press time, without keeping state. Pick the red cups and pick the overlapping apples. If the PickedCount values are equal, you have X apples overlapping X cups. There are many variations of this general idea. (I'm assuming you don't allow two apples on one cup.)
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, Yahoo [Bot] and 31 guests