[r115] Functions don't wait

0 favourites
  • 8 posts
From the Asset Store
Add calm and a lounge vibe to your games with these 8 tracks
  • Hi! It's me again torturing this poor function object

    I just discovered that functions seem to destroy their parameters (local variables and function arguments) before any action after a wait triggers. So basically

    on Function "test"
       -> wait 0.01
       -> Text: set text to Function.param(0)[/code:1y45gh1g]will always print 0
    
    one work around for now is to do:[code:1y45gh1g]on Function "test"
       + local static text persist = ""
       -> set persist to Function.param(0)
       -> wait 0.01
       -> Text: set text to persist[/code:1y45gh1g]
    
    little capx just in case
    [url=https://app.box.com/s/jzhqvlifaxdv5xyd0vma]functionsDontWait.capx[/url]
  • 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)

  • Ashley

    Alright (: since there are workarounds, I think it's not that big of a deal.

    Thanks for the explanation.

  • 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

  • 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 (:

  • aaallright i'll have a look this.

    Yann

    are you talking about the Timer behaviour of Rexrainbow?

    thanks for your help

  • philx

    Timer is now a native C2 behaviour.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)