Strange JavaScript node behaviour

Hello all,

I’m placing this topic in the General category since I’m not sure whether it falls under How-To or Issue Reporting.

I’m trying to create a JavaScript node that will output the number of entries in a CSV file, and update this number if the input file is modified. I have the functionality working (I think) using the example at the bottom of the ReloadResource() page of the manual but there are a couple of issues.

Firstly: The JavaScript node doesn’t work when the project is loaded. Using the “Reload Resource” function on the .js file it uses doesn’t seem to change anything, neither does disabling and re-enabling the node. However, it can be coaxed into working by instead selecting “Replace Resource” and replacing the .js file with the exact same file it was already using… What’s going on?

Secondly: When updating the CSV file, usually the JavaScript node will notice the update and change its output to the correct number of entries. However, sometimes the node will “miss” the update and output 0 instead and I’m not sure why. Continuing to update the CSV file often fixes this but doesn’t prevent the issue from appearing again.
I wondered whether it was maybe due to the file changing/node updating at the same time as the playhead resets to the start of the timeline but after experimenting with changing the timeline/node durations and messing about with continuous (delta) values it doesn’t seem to make a difference to the problem.
I tried to gain some insight using the log but I’m not sure I’m interpreting it correctly. Sometimes the log will print how long it took to load the source CSV input file multiple times in a row, as if it’s loading twice after being modified once, yet this doesn’t happen every time. Other times I’ll get a JavaScript type error telling me “Cannot call method ‘GetCSVFileContents’ of undefined” as if the system failed to find the input file. The confusing part is; why is it an intermittent problem? I can’t see why it doesn’t happen either every time or none of the time.

Here’s a link to a .zip of my project folder if you want to try to replicate this. You’ll need to “Replace Resource” the “csvLengthCounter.js” file with itself after opening the project.
When you play the project, the text on screen should cycle between all of the entries in the “Source.csv” file. Try adding or deleting entries from this file, then saving it while the project is playing. Usually it updates correctly but maybe 10% of the time for me the JavaScript node gets stuck and outputs 0, resulting in the text freezing on the first entry in the CSV file.

Any idea what the problem could be? Is there a better way to achieve what I’m trying to do?

Thanks for reading and I’m still having fun with Notch. :smiley:

Hi Colin,

First of all, let me apologise for not replying sooner - this issue appears to have fallen through the cracks.

Thanks for your very detailed bug description and repro - this helped a lot.

Upon further investigation, it appears that user-defined input parameters, so “csvPath” in your case, cannot be used in the Init() function. If you try to Log() “csvPath” in Init() then it returns “undefined”. This explains why you’re getting the “Cannot call method ‘GetCSVFileContents’ of undefined” error.

We’ve fixed this issue internally, so parameters can be used in Init() and it will be part of the next 0923 patch release.

Unfortunately, I wasn’t able to repro the issue where the node misses the update to the .csv file.