Event Loops, Functions and Script Functions

0 favourites
  • 11 posts
From the Asset Store
40 ambient sound loops. A wide selection of looping ambient sounds for different locations.
  • I am trying to figure out why I am getting some odd results and I'm sure its a lack of understanding with what's going on at certain points so I was wondering if someone could maybe explain the following which Im sure will lead me in the right direction.

    To help undertsand: I am loading a text file which contains lines of data, some have 500/600 lines and some might have 3000+ lines. What I ORIGINALLY did was create a loop to go through each line, read it, token it up, process some of the data (run the lines data though some calcs and functions) and then display it in a nice way at the end. The issue with this though was the "hang time" caused from all of the above happening in one tick.

    To solve this I did the following (which maybe the start of the issue)

    I crated a function with a line index parameter, which did all the reading and processing of a line at n index. At the end of the function I would simply call the function again with the next line index, until at the last line. This "function loop" works with some of the SMALLER files (upto around 500 lines) but what I found was anything over that and the function loop seemed to break... So I tried putting a "wait for previous action to complete" just before I call the function again with the next line index. Whilst this slowed the whole read process down, it seemed to work, read all lines just fine and does not hang the project. However, it is the start of some strange results from the data.

    In each function call, I grab the line of data (just comma delimited numbers and string's) (and sometimes the previous line) and I run them through various EVENT functions AND some JavaScript functions. But I'm finding some data to not be quite right, and its almost like its processing some lines at the wrong time in the function call, but they all use the same index var as the line ref.

    Here is a photo which shows the function loop I describe above.

    So is this because some of the functions I am calling are not finishing before it gets called again? Is there anything I need to do to these functions (both event funcs and JS funcs) to make sure they finish before continuing? The Event functions are NOT set to async nor are the JS functions.

    What I find strange is, nothing inside the function call actually has the little "wait" symbol (indicating a wait is required), yet putting the "wait for previous action to complete" before calling the function again does slow the loop down and loads all the lines, as apposed to if its not there only smaller files get loaded and big ones seem to break half way through reading the lines (500+)

    Thanks.

  • It's difficult to tell exactly what is happening, but since you said you are using some javascript, is it possible that some of those snippets are using the await keyword?

    If that is the case, the javascript is asynchronous and needs to be waited for before continuing if you want to keep things running sequentially.

    construct.net/en/make-games/manuals/construct-3/scripting/using-scripting/scripts-in-event-sheets

  • It's difficult to tell exactly what is happening, but since you said you are using some javascript, is it possible that some of those snippets are using the await keyword?

    If that is the case, the javascript is asynchronous and needs to be waited for before continuing if you want to keep things running sequentially.

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/using-scripting/scripts-in-event-sheets

    I have double and triple checked and all the JS I have written certainly doesn't and the 1 JS library that I'm using also doesnt appear to be doing.

    I will see if I can do a stripped back version of the issue and upload/send it over to you guys over to have a look. I cant quite fathom whats causing the issue despite doing some deep data analysis comparing the outcome of the line reads in C3 to other systems, very odd.

    As a test I changed the "wait for previous action to complete" to a wait for 0.5 seconds (between each line read) and loaded a file, but got the same results? Surely that would have given enough time to do everything, there only simple calcs and storing numbers in global arrays.

    What I don't get is why If I remove the "wait for previous action to complete" I cant fully load a file that has over 500 lines in? Its never the same line either, it just breaks at anything between 400 - 1000.

  • I have done a bit more digging and found that the data may actually be correct, I was receiving some odd numbers but found the other systems I was using to check/validate actually had filters that would omit data it deemed as inaccurate.

    So I have put in similar filters and now getting better results.

    However, I still cant work out the final issue of why I cant run the function loop as fast as possibly allowed in order to read the lines of data, but instead HAVE to have:

    "wait for previous action to complete" before reading the next line for it to work and load all the lines without breaking?

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi brother! don't you happen to have the ZIGZAG behavior for construct3? or any tutorial to pass that behavior to c3 file?

  • Hi brother! don't you happen to have the ZIGZAG behavior for construct3? or any tutorial to pass that behavior to c3 file?

    ?? Sorry, not a clue what your on about?

  • sorry, what happens is that the behavior I had in construction2 now that I am going to export to contruc3 tells me that I must have installed the ZIGZAG behavior made by rex.rainbow, the problem is that I can't find that behavior for contruc3, so it won't let me opening the project, I've looked for it everywhere and I can't find it, and removing it from the game would open new bugs.

  • sorry, what happens is that the behavior I had in construction2 now that I am going to export to contruc3 tells me that I must have installed the ZIGZAG behavior made by rex.rainbow, the problem is that I can't find that behavior for contruc3, so it won't let me opening the project, I've looked for it everywhere and I can't find it, and removing it from the game would open new bugs.

    You might want to open your own forum post as apposed to just jumping on other random ones?

    My original post has no link to what your asking for.

  • I understand, I apologize, I am somewhat desperate, in the forums that I have entered most of the people are inactive, I thought I could find help in the forums where they have been sharing them for a short time, again I apologize and withdraw.

  • I understand, I apologize, I am somewhat desperate, in the forums that I have entered most of the people are inactive, I thought I could find help in the forums where they have been sharing them for a short time, again I apologize and withdraw.

    That's fine, but your just plucking at straws and hoping for the best whilst clogging forum posts up with repetitive content.

    Post your own thread, with a relative title and someone who sees it will help. Trust me you will be much more likely to get a response that way rather than try at other users posts that are trying to resolve their own issues.

  • It's difficult to tell exactly what is happening, but since you said you are using some javascript, is it possible that some of those snippets are using the await keyword?

    If that is the case, the javascript is asynchronous and needs to be waited for before continuing if you want to keep things running sequentially.

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/using-scripting/scripts-in-event-sheets

    Just realised that it does thrown and error in the console when trying to load files without the "wait for previous action to complete" in place.

    Uncaught (in promise) RangeError: Maximum call stack size exceeded - in Parameter.js

    Why is this?

    EDIT

    I have changed this so now it doesn't run the function from within the function, but instead it runs it separately every tick. I then realised it was fixed at 60 fps (v-synced) so will only read lines at 60/s, changed it to unlimited and it now reads them as fast as it can, and successfully.

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