CREATE YOUR WORLD
Scripting

Script Import

4min

Other that being attached to a GameObject, ZEPETOScript can be used directly by other scripts.

You can simply import and use the ZEPETOScript the same way you would libraries or modules. In TypeScript syntax, you need to use the relative path to the ZEPETOScript file.

Considering the situation bellow, if you want to import ExtraComponent into ScriptImport, you would need to use the following syntax.

The following example is a declaration in ScriptImport.ts to call ExtraComponent.TS located in the lib folder.

TypeScript




Document image


👍 Tips

  • It's important to specify the path correctly when importing another TS file.
  • Please familiarize yourself with the relative path notation.
  • ./ denotes the current directory.
  • ../ denotes the parent directory, i.e., the directory one level up from the current directory.



You can access the exported functions and variables declared in the imported script by directly referencing them, like shown in the sample.

TypeScript




The following is a sample code showing the imported TypeScript.

TypeScript




Sample code for ExtraComponents.

TypeScript




Check out the test code output screen below.

2-10-1 (1).png
2-10-1 (1).png




Updated 10 Oct 2024
Doc contributor
Did this page help you?