Exporting functions; what am I doing wrong?

Hi there,

I’ve got a script named “coffee_script”. This is the script where I want most of my functions to be in.

A function in this script looks like this:

export function millisecondsToSeconds(milliseconds:number):number {
    return (Math.round(milliseconds/1000));
}

From a different script (on the “seen”-script in this case, positioned above the “seen”-scope), I want to call this function. I’m doing this like this:

var video_delay = 2000;
var video_countdown = symbol.nodes.coffee_script.millisecondsToSeconds(video_delay);

This produces an error:
error

As far as I’m concerned this is the way to go, but I’m obviously doing something wrong here.

1 Like

Haha. I’m posting this and while I’m reading the error message again in my post (probably the 20th time I’ve read this error), I realised that maybe the function itself is not being recognized. I thought this error had something to do with wrong ‘chaining’. I changed the order of the scripts (coffee_script was the last script in de hierarchy) so that coffee_script is the first script in de hierarchy and every script that calls milliseondsToSeconds() is underneath coffee_script. Everything works fine now.

I knew it had to be something simple. I didn’t thought it would be this obvious. :rofl:

1 Like

Hey Ferdy,

Glad you managed to get it working.

In short, script nodes are initialised in Hierarchy order, meaning your variable was attempting to access data from a function that wasn’t available to the program at the time it was called.

@simon’s comment linked below explains this in further detail:

All the best,
Seb

1 Like