How do I stop creating an object.?[SOLVED]

0 favourites
  • 9 posts
  • In my app when you do a correct answer an apple blooms on the tree and when it's wrong an apple falls. If you have it correct it adds 1 to ("correct" variable) and the code has created an instance of apple at a random place.

    so here are a few eg

    + System: Correct = 8
    -> Seed6: Set visibility Visible
    -> Apple: Set visibility Visible
    ----+ System: Trigger once
    -----> System: Create object Apple on layer 0 at (random(82,701), random(31,274))
    
    + System: Correct = 9
    -> Seed6: Set visibility Visible
    -> Apple: Set visibility Visible
    ----+ System: Trigger once
    -----> System: Create object Apple on layer 0 at (random(82,701), random(31,274))
    
    + System: Correct = 10
    -> Seed6: Set visibility Visible
    -> Apple: Set visibility Visible
    ----+ System: Trigger once
    -----> System: Create object Apple on layer 0 at (random(82,701), random(31,274))
    

    Now if you press the wrong answer it'll make an apple fall(using Bullet behavior) and adds 1 to "wrong" (variable)

    eg:

    + System: Wrong ≥ 1
    --------+ Apple: Is visible
    --------+ Seed6: Is visible
    ------------+ System: Trigger once
    ----------------+ System: Pick a random Apple instance
    -----------------> Apple: Set Bullet Enabled
    -----------------> Apple: Move to top of layer
    -----------------> Apple: Set Bullet angle of motion to 90 degrees
    
    ------------+ Apple: Y > 600
    -------------> Apple: Destroy
    -------------> System: Subtract 1 from Correct
    -------------> System: Set Wrong to 0
    

    The problem is let's say you're correct variable is currently 9 and you have 2 apples. You do the wrong answer so the correct variable should be = to 8 and one apple falls down. So you're left with 1 apple. Then let's say your next question is wrong. So the variable will become 8, and an apple falls down and you should have no apples left. But the problem is there will be an apple left why? because my code says if you have 8 as your correct variable it'll add one. Even if it's wrong. Is there a way to stop creating an apple?

  • Why did you start a new post about the same issue? Have you tried creating apples in a triggered event as I suggested you?

    You need to share your project file or at least a screenshot of your event sheet. The code you posted is difficult to read and it's hard to understand the structure of events and actions.

  • as a quick fix, you can try adding "Wrong=0" conditions to your events "Correct=8", "Correct=9" and "Correct=10". But then the order of events becomes important. I really suggest getting rid of the "state machine" code and do this with triggered events and functions.

  • as a quick fix, you can try adding "Wrong=0" conditions to your events "Correct=8", "Correct=9" and "Correct=10". But then the order of events becomes important. I really suggest getting rid of the "state machine" code and do this with triggered events and functions.

    What does 'state machine' mean. Can you write the code you suggested in the

    Code format?
    

    Thanks. Also here are the code screenshots.

    Correct

    Wrong

  • I don't see any pictures in your message...

    Like I said, try adding "Wrong=0" conditions to your events "Correct=8", "Correct=9" and "Correct=10".

    If this doesn't work, change the code to run only when you press the "submit answer" button, not on every tick.

  • I don't see any pictures in your message...

    Like I said, try adding "Wrong=0" conditions to your events "Correct=8", "Correct=9" and "Correct=10".

    If this doesn't work, change the code to run only when you press the "submit answer" button, not on every tick.

    I idd it right now

  • I don't see any pictures in your message...

    Like I said, try adding "Wrong=0" conditions to your events "Correct=8", "Correct=9" and "Correct=10".

    If this doesn't work, change the code to run only when you press the "submit answer" button, not on every tick.

    The first method didn't work because if it was 1 or something the whole thing would go. I dont understand the 2nd method

  • Okay so if we the 2nd method, Let's say you get the 1st answer correctly. Add 1 to correct and show seed. If it's the wrong the same thing but don't do anything and add 1 to wrong.

    But what about the 2nd question. There are 3 possibilities. If you get the 1st question wrong, and 2nd question correct it'll show seed. If you get both questions wrong. It'll show 'X'. If you get both questions right it'll show sapling. There are too many possibilities as you increase the question no.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The first method didn't work because if it was 1 or something the whole thing would go.

    I don't understand what it means - "if it was 1 or something the whole thing would go".

    If you add "If wrong=0" condition to all your "If correct=N" conditions, this will prevent from creating apples when the answer is wrong.

    I have asked you to please share your project file. It will be easier for me to fix your file, than creating the entire thing from scratch.

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