while loop uncertainties. Looking for help.

Discussion and feedback on Construct 2

Post » Mon Jun 10, 2013 2:33 pm

https://www.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 numScenarios is set to the width of the QA array 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 door.doorOption/doorText.specificDoorText = scenario.scenarioAnswer), I take the scenario they got right out of the QA array and subtract one from numScenarios//if they are wrong, points get added to delay time, the scenario stays in the QA array, and numScenarios stays the same. This process happens until numScenarios = 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. elephunky2013-06-10 14:39:53
B
8
S
3
G
1
Posts: 6
Reputation: 1,144

Post » Mon Jun 10, 2013 3:42 pm

[QUOTE=elephunky]
RUNDOWN:
(Note: At the beginning of the game numScenarios is set to the width of the QA array 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 door.doorOption/doorText.specificDoorText = scenario.scenarioAnswer), I take the scenario they got right out of the QA array and subtract one from numScenarios//if they are wrong, points get added to delay time, the scenario stays in the QA array, and numScenarios stays the same. This process happens until numScenarios = 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. [/QUOTE]

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!
B
24
S
9
G
7
Posts: 756
Reputation: 7,292

Post » Mon Jun 10, 2013 4:16 pm

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....
B
8
S
3
G
1
Posts: 6
Reputation: 1,144

Post » Mon Jun 10, 2013 5:20 pm

[QUOTE=elephunky] 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....[/QUOTE]

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. :)
B
24
S
9
G
7
Posts: 756
Reputation: 7,292

Post » Mon Jun 10, 2013 7:09 pm

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:
https://www.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.
B
8
S
3
G
1
Posts: 6
Reputation: 1,144


Return to Construct 2 General

Who is online

Users browsing this forum: dgiger68 and 2 guests