How to use function variables when function contains waits

0 favourites
  • 2 posts
From the Asset Store
Add calm and a lounge vibe to your games with these 8 tracks
  • I have a little problem writing functions with System.Wait in them. For example this works just fine:

    producing

    but simply adding a wait like

    shows this:

    and this is because, as I understand, the function parameters are no longer accessible from the point after the Wait, and hence are 0. If we use local variables, the same problem occurs. The scope of the local variables seems to behave similar to the Function parameters, except now the string is blank, so there is nothing to see.

    Making the local variables static sort of solves this problem but brings in another issue. Separate calls to the function have access to the same variables, which can lead to unexpected results:

    (I've added a random to the Y value to demonstrate that there were two calls that essentially are using the values from the second call.)

    One solution might be to pull the wait out of the function. However, if the wait is variable and a part of the function parameters, pulling this out means I have to do the wait before every single call to the function, which is bad design.

    My question is, is there a workable way to hold function call specific data between waits that don't interfere with other calls to the function? Function scope variables (that would be passed through to the events after waits) would be very nice to have, and in fact function signatures (with parameter guidance like inbuilt functions) and autogenerated variables in the "On <function>" event would be awesome.

    Capx used: https://www.dropbox.com/s/ze7gmtmdevaro ... .capx?dl=1

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi, did you find solution? I am strugling with the same problem.

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