How Import a script from another tab or external library

I defined a Function in one tab (Script) that I want to call again in another tab (Typescript). The code editor sees the function and gives no errors but when you run it the system can’t find the function. The import ‘Script’ makes no difference either way.

Also, am I right to assume that it is impossible to import other library’s as well since Cospaces seems to have written the compiler to nerf industry standard things like console.log() and while() functions?

Thanks,
Jim

1 Like

Seems like you need to use a class+method export, rather than a function.

Assuming saySomething is your function, you’d need something like this in your Script:

export class Something {
    public static saySomething(item: object, dialog: string, seconds: number){ 
        //function code here
    }
}

then in your calling script have:

import {Something} from "./Script";
Something.saySomething(tri, "Say something", 2);

See this simple remixable example:

Can’t comment on your 2nd query.

Hope that helps! Let me know if you have any further queries about this. If this solves your problem, please mark this post as the Solution.

Many thanks,
Geoff @ TechLeap

1 Like

Thanks @techleapnz for the detailed answer.

1 Like

This also works for function exports as well:)

export function square(x) { return x*x };
import { square } from './Exports';

Debug.log(square(3));
1 Like

Great detective work, @jlfjlf ! So it’s just the export/import statements which are crucial here. :ok_hand: