How do I wait until a function has completed?

Get help using Construct 2

Post » Sun May 10, 2015 3:02 pm

Similar to my previous post, but that looks as though it's solved. I've solved part of the problem but I still need to know if there's a way to wait until a function has completed all of it's processing. I want my game to wait and disable the 'Next Turn' button until processing is complete (it's turn-based). Right now, I can disable the button, put in a tiny pause to show the new state of the button, then jump to my functions, then re-enable the button 'after' the functions, but what it does is, it calls the functions which begin processing and then immediately re-enables the button (even if that line is 'after' the functions or at the end of a function), meaning you can keep clicking for more turns while this one is still being processed.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sun May 10, 2015 3:08 pm

var = 1

some event:
var = 1
call function


on function:
do stuff
var = 0


var = 0
trigger once:
set text: "the function has finished"

(or use wait for signal and signal)
Last edited by mindfaQ on Sun May 10, 2015 3:36 pm, edited 1 time in total.
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 3:11 pm

ehhhmm..

Aren't the functions performed in one tick?

What is it that should be waited for?
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 3:35 pm

Normally they are, if you have no wait actions etc in them.
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 4:16 pm

My game is turn-based and the functions can take a long time (several seconds on my phone, less than a second on my PC). When you click the 'Next Turn' button, I need to show a 'Please Wait' type message and have the button(s) become disabled. Right now, you can click the button over and over while it's processing the functions and it basically queues more turns.

From what I can tell, the functions aren't performed in one tick. It appears to call each function immediately but then process them in a background thread or something, since you can still press the button while it's processing the functions.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sun May 10, 2015 4:22 pm

Could you give an example of what your function looks like?
As far as I know a function is a triggered event that will be handled in the tick it is called, unless you use wait actions inside the function itself.
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 4:26 pm

Here's an example of what I mean. If you click on the right-hand box, it should change colour, then you'll see the left-hand box pause while it's processing the loop on line 3 (the timer has been added otherwise you don't even see the frame-change). The problem is, if you click really quickly, it queues up more presses. Adding 'Sprite Animation frame = 0' the line 1 conditions doesn't stop this.

https://dl.dropboxusercontent.com/u/112519761/button.capx
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sun May 10, 2015 4:29 pm

Ok, so what you're saying is, if the function is very slow (e.g 1 second) the entire game should lock up for 1 second and nothing else should be processed? That's fine and would make my life easier, but then I don't understand why it's queuing up extra presses of the mouse.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Sun May 10, 2015 4:42 pm

First of all I don't see any functions, just a loop for 2.000.0000
this means you are processing 2 million events in one tick.

if you set the loop to start the next tick (by adding a wait 0 command) it works.

https://www.dropbox.com/s/73jo0hdu8tmpr ... .capx?dl=0

It's not saving up extra presses as far as I can see..
In your example there is a timer function which is restarted every time you click..
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 4:50 pm

Yes, I'm aware that it's not actually a function (it is in my main program). I'm just using the word generically (and wrongly, sorry). What I mean is, a block of code which takes a long time to complete. The loop here is just to demonstrate. Are you saying that C2 will literally do nothing else while those 2 million events are processed? If so, I don't see why I can double-click on the sprite.

I need to update so I'll check your example.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Next

Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 25 guests