How do I stop my math game from crashing?

Get help using Construct 2

Post » Wed Jun 08, 2016 9:20 pm

Hi,

I'm making a fractions sum game. Getting the numbers at random. Now, the sum of the 2 numerators cannot be greater than the denominator, if this happens, I'm re-rolling the numbers, sometimes it works, and sometimes the game crashes, I don't know why.

For the people kind enough to take a look at the code, go to the sheet "gameSheet", and take a look at line 35, the function "operation".

Thanks!

Capx file:
https://db.tt/sp6VTygX
B
26
S
8
Posts: 84
Reputation: 1,722

Post » Wed Jun 08, 2016 9:45 pm

Get rid of the "Wait 0"s.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Wed Jun 08, 2016 9:52 pm

blackhornet wrote:Get rid of the "Wait 0"s.

Still crashes :(
B
26
S
8
Posts: 84
Reputation: 1,722

Post » Wed Jun 08, 2016 10:56 pm

Wait will not pauze the tick. It just postpones the actions in time, the events that follow just continue to run.

"Wait 0 seconds" is SPECIAL, it postpones the following actions until the end of the event sheet.

There is a wait before the function call. So the system sets the function call aside and runs some ticks. Then, when the wait (0.2 seconds) is over, it calls the function. There is no way to know exactly at what point the tick is now in the events.

So, the function gets called, denominator gets a new value. And it this point, due the first wait call, the events have been on the end of the tick. So mostly num1, num2 and result get a value.

I think the while loop can try like 4 or 5 times, then it all get caught up. If it dont guess more then 4/5 times it will probaly work, it has been a some times at the end of the events during the wait before the function call. But after that, the event ticker is caught up in the while loop, because it runs that while loop. And when the 'result' is illegal, it can be bigger then any denominator can be. But now, the event sheet wil not be at the end anymore, the moment where the waits postponed the actions. So, denominator gets a new value, but num1,num2 and result will never again get a new value. So the while keeps gooing. And thats a endless loop = a non responsive game. Or as you say = a crash.

Solution = Do not use 'waits', use timers.
The waits in the function are totaly not needed.

edit, they gave you that solution allready, i see.
restart the browser, it will work
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Jun 08, 2016 11:00 pm

Two issues: if num1=0 and num2=0, nothing is shown.
Shuffle is being called repeatedly in event 57 as i=4.

Double check your logic.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Wed Jun 08, 2016 11:07 pm

blackhornet wrote:Two issues: if num1=0 and num2=0, nothing is shown.
Shuffle is being called repeatedly in event 57 as i=4.

Double check your logic.

I'm setting num2 from 1 onwards so it's never 0 and 0.
When shuffle is called im adding 1 to i, thanks for leting me know!
B
26
S
8
Posts: 84
Reputation: 1,722

Post » Wed Jun 08, 2016 11:08 pm

99Instances2Go wrote:Wait will not pauze the tick. It just postpones the actions in time, the events that follow just continue to run.

"Wait 0 seconds" is SPECIAL, it postpones the following actions until the end of the event sheet.

There is a wait before the function call. So the system sets the function call aside and runs some ticks. Then, when the wait (0.2 seconds) is over, it calls the function. There is no way to know exactly at what point the tick is now in the events.

So, the function gets called, denominator gets a new value. And it this point, due the first wait call, the events have been on the end of the tick. So mostly num1, num2 and result get a value.

I think the while loop can try like 4 or 5 times, then it all get caught up. If it dont guess more then 4/5 times it will probaly work, it has been a some times at the end of the events during the wait before the function call. But after that, the event ticker is caught up in the while loop, because it runs that while loop. And when the 'result' is illegal, it can be bigger then any denominator can be. But now, the event sheet wil not be at the end anymore, the moment where the waits postponed the actions. So, denominator gets a new value, but num1,num2 and result will never again get a new value. So the while keeps gooing. And thats a endless loop = a non responsive game. Or as you say = a crash.

Solution = Do not use 'waits', use timers.
The waits in the function are totaly not needed.

edit, they gave you that solution allready, i see.
restart the browser, it will work


Thanks for the explanation. I took out every "wait" and it's working now!
B
26
S
8
Posts: 84
Reputation: 1,722


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests