wait() makes parameter disapears

Discussion and feedback on Construct 2

Post » Thu Jan 15, 2015 7:04 pm

Does anybody knows why this happens?
The first alert() shows me the string that I´m sending to the funtion, the second one shows me "0" (see img).
You do not have the required permissions to view the files attached to this post.
B
18
S
4
G
1
Posts: 143
Reputation: 1,868

Post » Thu Jan 15, 2015 9:54 pm

Wait doesn't work with events that work only trough single tick.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Thu Jan 15, 2015 10:25 pm

Sorry @megatronx, I did not understand. Do you mean that Function works in a single tick?

but why Wait() clear the parameter? It sounds like a bug to me.

First alert() = "My String"
wait() 0.3
Second alert() = "0"
B
18
S
4
G
1
Posts: 143
Reputation: 1,868

Post » Thu Jan 15, 2015 11:05 pm

frcol wrote:Sorry @megatronx, I did not understand. Do you mean that Function works in a single tick?

but why Wait() clear the parameter? It sounds like a bug to me.

First alert() = "My String"
wait() 0.3
Second alert() = "0"


Yes, function works single tick. That's where the problem is most probably coming from.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Fri Jan 16, 2015 10:02 am

It doesn't work because the function ends when you 'Wait'. It executes like this:

1. 'On function' triggers
2. First action retrieves correct parameter
3. Wait action is used
4. The function ends and execution returns to the rest of the event sheet
5. Event sheet keeps ticking for a while during the 'Wait', until the time expires
6. The last action tries to retrieve a function parameter, but it's not in a function any more, so returns the default 0.
Scirra Founder
B
395
S
232
G
88
Posts: 24,368
Reputation: 193,746

Post » Fri Jan 16, 2015 4:18 pm

Store the param from a function in a local variable below the function call. And you should be good.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Mon Jan 19, 2015 6:13 pm

Sorry the delay, I was travelling.

@jayderyu I had thought to do that, I´ll try now that I´m back.

@Ashley, don´t you think that it would be a good ideia to put an advise into Wait or Function in the manual telling that we can´t use wait() into the Function? Or maybe in this tutoril https://www.scirra.com/tutorials/56/how ... ait-action, in the "For advanced users" section.

I think it´s stranger in any part of the manual this "collateral effect" is not mentioned, or I´m missing something?
B
18
S
4
G
1
Posts: 143
Reputation: 1,868

Post » Wed Jan 21, 2015 1:57 pm

Local variable did not work.
Just worked in global variable.

EDIT: Group local variable not work, it´s something that does not sounds confortable to me.
B
18
S
4
G
1
Posts: 143
Reputation: 1,868

Post » Wed Jan 21, 2015 4:17 pm

@frcol did you make sure the variable was static?
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Jan 21, 2015 5:56 pm

Hi @Aphrodite,
to tell you the true, I did not think in set it as STATIC. Since it is in the "local group" scope.
I´m thinking like a programmer, inside a function, we do not make a variable static just to access it.
I would think in use it as static if I would use this code in other object and want to keep its value (because each instance would delete its content)

But now, understanding that when Wait() is called the Function end ("cleaned"), keep it static makes sence.
Am I correct?
B
18
S
4
G
1
Posts: 143
Reputation: 1,868

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Artpunk and 9 guests