how do you call function from a different file?

Hi, Right now i’m writing a program contain multiple scripts, basicly a main script calling other side scripts. But on those side script i need to use one of the main script function, how can i link them together? Thx

short answer: Restructure your scripts. The main script function that’s needed in the main script and in side scripts isn’t a main script function.
another short answer: write the function (which should be self-contained, using no globals) as a script. Load that script into a variable in the main function; pass the variable to the side script; or have each side script load the function when necessary.

One approach is to pass the main script object to the handler that needs it:


-------
--MAIN SCRIPT

	property libStore : {}
	on loadLibs()
		set libStore to load script file "Macintosh HD:warbleLib"-- your path here
	end loadLibs

	on furble()
		display dialog "furbling now..."
	end furble

	on run
		loadLibs()
		tell libStore to warble(me) -- passes main script object (i.e. 'me') to warble handler
	end run

-------

And the library script, which gets loaded into main script by loadLibs():


-------
--LIBRARY SCRIPT

	on warble(mainLib)
		tell mainLib to furble()
	end warble

-------

has (WWSND?)