while loop uncertainties. Looking for help.

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • dropbox.com/s/35wc65vrns7txla/SB.capx

    I have temporarily disabled the part of my game file that seems to be causing the problem.

    This is a difficult error for me to solve, because I am not getting any error message when I test my game. Instead, it makes the call to move on to the next screen (main), but the page does not change, and it seems to almost 'freeze up'.

    Note: this does not happen when the while loop is disabled, which is why I have pointed to it as the error origin.

    RUNDOWN:

    (Note: At the beginning of the game <font color=blue>numScenarios</font> is set to the width of the <font color=red>QA array</font> to keep track of how many questions there are.)

    What I expect to happen:

    The while loop begins, it prints the first scenario, the user has a chance to touch/click which door has the correlating, correct answer - they move along a path to the door they touched, once they arrive to the touch coordinates: if they are right (if the <font color=green>door.doorOption</font>/<font color=orange>doorText.specificDoorText</font> = <font color=magenta>scenario.scenarioAnswer</font>), I take the scenario they got right out of the <font color=red>QA array</font> and subtract one from <font color=blue>numScenarios</font>//if they are wrong, points get added to delay time, the scenario stays in the <font color=red>QA array</font>, and <font color=blue>numScenarios</font> stays the same. This process happens until <font color=blue>numScenarios</font> = 0. Then the game is over and it takes you to the summary page.

    However, I am not sure what part of my while loop is causing the page to get hung up.. and hoping that another pair of eyes can catch it, or suggest another way to go about doing things.

    Thank you all very much. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • RUNDOWN:

    (Note: At the beginning of the game <font color=blue>numScenarios</font> is set to the width of the <font color=red>QA array</font> to keep track of how many questions there are.)

    What I expect to happen:

    The while loop begins, it prints the first scenario, the user has a chance to touch/click which door has the correlating, correct answer - they move along a path to the door they touched, once they arrive to the touch coordinates: if they are right (if the <font color=green>door.doorOption</font>/<font color=orange>doorText.specificDoorText</font> = <font color=magenta>scenario.scenarioAnswer</font>), I take the scenario they got right out of the <font color=red>QA array</font> and subtract one from <font color=blue>numScenarios</font>//if they are wrong, points get added to delay time, the scenario stays in the <font color=red>QA array</font>, and <font color=blue>numScenarios</font> stays the same. This process happens until <font color=blue>numScenarios</font> = 0. Then the game is over and it takes you to the summary page.

    However, I am not sure what part of my while loop is causing the page to get hung up.. and hoping that another pair of eyes can catch it, or suggest another way to go about doing things.

    Thank you all very much. <img src="smileys/smiley1.gif" border="0" align="middle" />

    C2 event sheets are evaluated as whole every tick. So if you have a while loop, you should also break out of it somehow, otherwise the tick will never complete. You don't need 'game loop' as you'd have in traditional programming. :) I don't see any need for the while in there at all. You should adjust your thought process more towards 'trigger based', so think what should happen when player clicks a door, what should happen when a layout starts etc. It will help you a lot in getting best out of construct 2!

  • thanks. still adjusting..

    But... doesn't the condition under the while loop 'break out of the loop'? I thought that is what the condition was for.. to tell it when to stop and move on?

    Because if I want a group of actions to happen a certain # of times, i.e. I want it to run until a variable reaches 0, is there a better way to do that?

    Should I have the group of actions run from a blank event, then have a sub-event after the actions that says 'if ____ , repeat group of actions' 'else ____' ?

    for example, the process I want repeated until global var numScenarios=0 is a group of actions that includes choosing the door, checking if the answer is right, and having something happen if it is correct, and something else happen if it is incorrect. Then I want this to happen all over again with a new scenario.

    My measly mind just cant understand how this would happen over and over again without something like a while loop telling it to keep going UNTIL numScenarios=0....

  • thanks. still adjusting..

    But... doesn't the condition under the while loop 'break out of the loop'? I thought that is what the condition was for.. to tell it when to stop and move on?

    Because if I want a group of actions to happen a certain # of times, i.e. I want it to run until a variable reaches 0, is there a better way to do that?

    Should I have the group of actions run from a blank event, then have a sub-event after the actions that says 'if ____ , repeat group of actions' 'else ____' ?

    for example, the process I want repeated until global var numScenarios=0 is a group of actions that includes choosing the door, checking if the answer is right, and having something happen if it is correct, and something else happen if it is incorrect. Then I want this to happen all over again with a new scenario.

    My measly mind just cant understand how this would happen over and over again without something like a while loop telling it to keep going UNTIL numScenarios=0....

    I'd do it like this (if I understood what you are aiming for correctly):

    • When player clicks on door(on touched trigger), check if the answer is correct or not. Do necessary actions.
    • If numScenarios =0, go to next scenario. This doesn't need a while loop, just leave condition 'numScenarios= 0' at your events with related actions. When numScenarios = 0, those actions will run.

    You could think it like that there is a constant while loop automatically going through the event sheets and checking what conditions should be triggered. :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • oh good way to think about it! thank you so much.

    I feel like I am getting much closer.

    I used your advice and just used a condition to trigger my actions.

    However, since I set my numScenarios to the width of a given array at the beginning (which will be dynamic), I used 'as long as numScenarios>0..do this' type of thing, and will be subtracting from numScenarios based on when the user makes the correct choice (if incorrect, it stays same). So once they get them all right and numScenarios=0 it will no longer perform the actions.

    Now if I could bug you about my next problem?

    If you want me to post another forum about it I completely understand!

    You have been very helpful in broadening my understanding.

    Here is a new link to my improved game:

    dropbox.com/s/3ttrnuch7efpkta/SBclose.capx

    What is happening now:

    It grabs the scenario from the array correctly & displays it, the pathfinder is working because the person-looking object moves to the correct door.

    But, I can not figure out why events 12 & 13 are not working properly (i.e. the feedbackCorrect/feedbackIncorrect is not showing up etc.)

    There are no errors, and in my console it seems to keep printing the first several actions under the guessProcess... I feel like that is bad? By that I mean should it really be printing those actions over and over again? I doubt it.. but why is it doing that? And why aren't the other actions properly running when they are triggered? (by triggered I mean when the user clicks on the door with the correct/incorrect answer).

    Is it because, within my conditions on events 12 & 13, I am checking if two instance variables - which are text values - are = to one another? I know that in other programming you have to use ".equals" for strings instead of =... but = seems to be the only option here.

    Is what I am doing possible ?

    Thank you again.

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