How do I implement while

0 favourites
  • 7 posts
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you really need the variable then? The "Overlapping" condition is giving you the data you need.

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

  • 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

    >

    > 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

  • When you press the button, check if the apple overlaps the cup. No variable needed.

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

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

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