wait() makes parameter disapears

  • 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).

  • Wait doesn't work with events that work only trough single tick.

  • 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"

  • 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.

  • 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.

  • Store the param from a function in a local variable below the function call. And you should be good.

  • 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?

  • Try Construct 3

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

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

  • frcol did you make sure the variable was static?

  • 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?

  • I just spent all the day trying to understand why sometimes the function.param was not collecting the passed value and fortunatly i came to this topic!

    Have to say that, since i was born with "basic" language, is really hard for me to get into construct 2 "wait"

    It' s really important to me to use a wait command to have all the sprites, text and effects appear in the right sequence and timing.

    If wait function won't work inside a function, how can be the right "timing" achieved?

  • Probably not best to use a function when timing is involved like this! Functions are supposed to be instantaneous - when you call them, they must finish before the processor moves on to anything else. Wait actions go against this. Just use regular events, or multiple spaced-out function calls.

  • Create an array object under on function condition by action, I.e. Create at runtime, save parameters into this array to keep them.

    When left function call, remember to destroy this array.

    Edit

    http://c2rexplugins.weebly.com/rex_fnparam2array.html

    This plugin could help user to create and save all parameters into an array in an action.

  • Oh my... really sorry but i see this reply only now... do not know why! :O Maybe i was dunk

    Thanks REX, i immediately try your plugin! (i'm already using the chess ones )

    Seems you are the Wishmaster

  • I just spent the last hour trying to figure out why my param strings weren't passing properly. Turns out I had a delay in the function. Couldn't figure out for the life of me why it wasn't working.

    I can't say thank you enough. Saved me, likely, hours of trying to figure out the issue.

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