[r115] Functions don't wait

Bugs will be moved here once resolved.

Post » Fri Jan 11, 2013 3:11 pm

Hi! It's me again torturing this poor function object :D

I just discovered that functions seem to destroy their parameters (local variables and function arguments) before any action after a wait triggers. So basically
Code: Select all
on Function "test"
   -> wait 0.01
   -> Text: set text to Function.param(0)
will always print 0

one work around for now is to do:
Code: Select all
on Function "test"
   + local static text persist = ""
   -> set persist to Function.param(0)
   -> wait 0.01
   -> Text: set text to persist


little capx just in case
functionsDontWait.capx
Last edited by Yann on Sun Sep 14, 2014 8:22 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Jan 15, 2013 3:27 pm

I'm afraid this is by design, or something we won't fix at least, since this is what is expected to happen given the current design of the wait action. If you set the text of a text object, then retrieve it after a wait, it may be different if it was changed during the wait time. Likewise the function has ended so the parameters are now different or no longer there. (It's like using Function.Param(0) in an event outside a function)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Tue Jan 15, 2013 8:57 pm

@Ashley
Alright (: since there are workarounds, I think it's not that big of a deal.
Thanks for the explanation.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Feb 07, 2014 2:07 pm

i was friggin happy about this workaround until i found out it's not working for me if i call the function at the same time with different parameters.

i have multiple spaceships which spawn different bullets. they are called p1_ship, p2_ship, p3_ship and p1_bullet, 02 ...
i then have each bullets and ships in a family called all_ships and all_bullets.

all_bullets | on created -> function | call "cooldown" (all_bullets.player).     - player is an instance variable which stores the player nomber to whom the bullet belongs

then:
+ local static text persist = " "
function | on "cooldown"
-> system | set persist to function.param(0)
-> [engine] | set value at (persist,1) to 1
-> system | wait [upgrades].At(persist,13),2,2) seconds
-> [engine] | set value at (persist,1) to 0
-> system | set persist to " "

where these are [arrays]

this works fine if everybody shoots at different times, but if all characters shoot together, only one of them will get his cooldown reset after the wait time.

i think this is because they all use the same local text variable when they call the function.

is this possible? could you think of a fix?

cheers! phil
B
23
S
6
G
5
Posts: 132
Reputation: 4,487

Post » Fri Feb 07, 2014 8:09 pm

@philx
You could use a timer behavior on your ships and start the timer + set an instrance boolean "cooling" to true when they shoot
When the timer is over (triggers the on Timer event), they can shot again (you switch the "cooling" variable back to false)
Make sure you only shoot when cooling is false (:
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Feb 07, 2014 9:03 pm

aaallright i'll have a look this.
@Yann
are you talking about the Timer behaviour of Rexrainbow?

thanks for your help
B
23
S
6
G
5
Posts: 132
Reputation: 4,487

Post » Fri Feb 07, 2014 9:40 pm

@philx
Timer is now a native C2 behaviour.
ImageImageImage
B
67
S
19
G
123
Posts: 3,209
Reputation: 73,905

Post » Tue Apr 22, 2014 5:34 am

Hey just got some problems using wait inside functions but this entry clarify it all. I would suggest to put in the documentation on function about not using a Wait action inside a function!. It will help people :)
B
10
S
2
G
1
Posts: 48
Reputation: 1,265


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests