How do I wait until a function has completed?

Get help using Construct 2

Post » Sun May 10, 2015 4:53 pm

Yes, I'm struggling to demonstrate this properly in an example. The reason for the timer is that without it, what it does is change to the next frame then in the same tick, start the loop, meaning that you don't see the frame change (because presumably everything updates at the end of the tick?). So it changes frame then immediately pauses before showing the change, then changes back (all in the same tick, so nothing happens).

It's hard to see the extra presses, it's not a very good example. If you really hammer at the mouse, you may see it flicker and restart another loop.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sun May 10, 2015 4:57 pm

It's the same in your example. It might be hard to notice, you need to double-click the box and you may see it pause, then change back, then pause again. Try it a few times. Your PC might be faster than mine so it might be unnoticeable.

I'm trying to work out a good way of demonstrating. But basically, stuff is still being processed while it's in that loop (mouse clicks at least).
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sun May 10, 2015 5:07 pm

In theory the program should indeed freeze while the event is repeated 2 Million times.
I must admit it seems the mouse-clicks are being registered while the eventsheet is executing and as such used the next time the eventsheet is read (which is actually kinda logical when you think of it, when would mouse-clicks be registered otherwise?).

I'm not sure why anyone would need a loop repeating 2 million times, though..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun May 10, 2015 5:23 pm

Like this it works (the wait introduces a wait time of 1 frame after freeze until the touch gets unlocked again, means clicks during the freeze will have had no effect)
Image

I'd still suggest writing the code in a way that doesn't freeze up your game.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Sun May 10, 2015 5:55 pm

That seems to work mindfaQ, I'll try implementing that into my game.

Littlestain, bear in mind that the 2 million loop is only to demonstrate the problem.

I don't particularly mind locking up the game during the turn process, though I agree that it's not ideal and it's poor programming. What I was trying to do was to have a message to tell the player that it's processing and disable any buttons so that the player can't make alterations during this time. Whether it's frozen or unfrozen during that time is no big deal as far as the game is concerned. But that wasn't working the way I was doing it, though it looks like the correct use of 'wait' will fix it.

I'm not actually sure how to stop my processing from freezing up the game, on my phone at least. It's got a lot to do and I don't want the player interfering during that time anyway.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Tue May 12, 2015 3:05 pm

If anybody reads this with a similar problem, I should point out that mindfaQ is spot on when he says that you shouldn't write code that freezes up C2 anyway. The solutions above (putting in timers and waits) are only needed because my processing was taking so long and causing C2 to freeze, but it's much much better (and easier to code) if you can split up your processing into smaller chunks, allowing C2 to do it's stuff. So in my case, I was processing orders for 64 teams in a single loop, but it's much better to do 1 team during each tick. That way, I can display my 'Please Wait' message and disable the 'Next Turn' message, whenever a 'processing turn' variable is set and allow the program to continue without interference from the player. When the 64 teams are complete, the variable is set back to zero and the buttons are re-enabled.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Previous

Return to How do I....?

Who is online

Users browsing this forum: adventurist and 25 guests