Functions and CSV plugin - having an issue with functions blowing away data

0 favourites
  • 5 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • So I am using the CSV plugin by Rex. I've been using it for years because I like it better than Construct's arrays or any other database format. I just build spreadsheets with as many rows and columns as I like and it allows me to save all the data I want between layouts and I can reference it by column name.

    So I started using the new functions-built-in with a return and I ran into a problem.

    I made a function that cycles through my CSV database crunching the data and returning a value.

    But I also have some code that cycles through the CSV but then calls this function above. So both are reading the CSV and I'm using "For Each Column" in both which utilizes the CSV.CurRow and what happens is the CSV-data after the function call (that also references the CSV) is all zeroed out.

    I tried a "Wait for Previous Actions" but it didn't work.

    Is this a limitation with the CSV plugin or something I'm doing wrong with Construct built-in Functions?

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm going to hazard a guess that the plugin clears the current iterator value after it's finished a loop. Which is fine, except if you have a nested loop then the iterator value isn't usable after the inner loop has completed.

    loop {
    	// current iterator = outer
    	loop {
    		// current iterator = inner
    	}
    	// current iterator = null
    }
    

    The expected behaviour for using an expression at an invalid time it to emit some sort of null value ( empty string for string expressions, 0 for numerical ) so accessing iterator values when the plugin doesn't have an iterator would probably return zeroes.

    Typically a plugin can solve this by storing the current iterator before starting a loop then restoring it after the loop has completed.

  • Nepeo that would make sense.

    Each row in my CSV is a "level" and stores info about that level. so when the player goes back to that level it "remembers" its shape/size, type, enemies etc...

    So I could probably fix it if I make my own loop variable? I could easily do this since I have a static number of rows.

    Does a function complete in one tick?

    i.e

    if I loop through CSV and inside I loop through the entire CSV to get aggregate data and return it, then apply that to each row. That will work yes?

  • Timing wise calling a function is the same as say... a nested event block. So it should complete during the current tick. Provided you don't have something like "wait N seconds" or "wait for previous async actions" inside the function.

    Yeah it sounds like you could fix it by stashing the data into a variable, or some other data structure. I don't think I have the CSV plugin lying around to check, but you might be able to check my guess by looking at the debug values. If it has something like "current iterator value" you can step through the event block and see what it changes to.

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