functions in other scripts

Hi,
I’m a novice in using Eggplant, and I need some help.
How can I make a call to a function in another script file?

thank you

Currently there is only one syntax that allows you to call a handler declared as a function from another script, and it looks like this:

["scriptName" functionName:parameterList]

You can still get the return value by putting this into an expression:

put ["scriptName" functionName:parameterList] into myVar

or you can use this alternative syntax:

["scriptName" functionName:parameterList]
put the Result into myVar

where “the Result” is a special SenseTalk variable that stores the return value of the previous command.

The other syntaxes (run, send) work only with command (on) handlers. Note that a command can also be passed parameters and have a return value (accessed through “the Result”), so you might consider rewriting your functions as commands – all you need to change is the declaration.

There are a couple other relevant tips I can share: You can access commands and functions in another script as if they were part of your calling script by issuing the following command at the beginning of the calling script:

start using "scriptName"

This works rather like an include statement, but the action can also be reversed later in your script like so:

stop using "scriptName"

Also, if you create a script that contains nothing except a single function with the same name as the script, calling that script will execute the function.

Hi,

I have tried using script using “scriptname” syntax. it didn’t work for me :cry:

i have created a a script (testfunction) having a function to fetch the data from the file.(getfiledata)

When used like : start using “testfiledata” gives follwoign error:

“STAlert: Bad Value or object expression. Looking for object or script identifier.”

could you please guide me using the function written in different script? Also is there another method we can use.

Using a resource located in a different suite can be done by adding the other suite as a helper. Helper suites can be specified from the Helper’s tab from a suite editor. You can also reference resources from other suites by opening a suite from within a script using the openSuite function.


openSuite "/path/to/suiteName"

When a suite is open, all of its images and scripts, as well as those of its Helper Suites, are available for use by the executing script. All images and resources that are not found in the local suite, will be searched for within any Helper suites. This allows you to create core suites that define
common functionality you can reuse in many other suites.

As mentioned in a previous post above, you can include all handlers/functions declared in another script with a “start using ‘scriptName’” declaration.

Let’s suppose that you had a script named functions.script that contained nothing but functions. Invoking these functions from a script in the local suite could be done as follows:


start using "functions"

// someFunction is a function in functions.script
put someFunction()

…or


// method one
put functions.someFunction()

If you want to call a function/handler that is declared in a script contained in another suite you MUST first open the suite or already have the suite added as a helper suite.


openSuite "/path/to/someSuite"

// functions script contained in someSuite
put functions.someFunction()