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 import extracomponent from ' /lib/extracomponent'; 👍 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 this gameobject addcomponent\<extracomponent>(); const extracomponent = this gameobject getcomponent\<extracomponent>(); // get value by method call const count = extracomponent getcount(); // set value by method call extracomponent setcount(0); // get public property const resultstring = extracomponent stringproperty; the following is a sample code showing the imported typescript import { zepetoscriptbehaviour } from 'zepeto script'; import { text } from 'unityengine ui'; // import custom script from path import extracomponent from ' /lib/extracomponent'; export default class scriptimport extends zepetoscriptbehaviour { public resultui text; private extcomponent extracomponent; start() { // add script component this gameobject addcomponent\<extracomponent>(); this extcomponent = this gameobject getcomponent\<extracomponent>(); } update() { // get value by method call const count = this extcomponent getcount(); if (count > 10) { // set value by method call this extcomponent setcount(0); } // get public property const resultstring = this extcomponent stringproperty; // print result console log(`result ${resultstring}`); this resultui text = resultstring; } } sample code for extracomponents import { zepetoscriptbehaviour } from 'zepeto script'; export default class extracomponent extends zepetoscriptbehaviour { public stringproperty string; private message string; private count int; start() { this message = "hi zepeto!"; this count = 0; } update() { this stringproperty = `${this message} ${this count++}`; } getcount() { return this count; } setcount(newcount int) { this count = newcount; } } check out the test code output screen below