CREATE YOUR WORLD
Scripting
Hello ZEPETOScript
12min
what is zepetoscript? zepetoscript is a scripting language used for creating zepeto world it supports the typescript programming language zepetoscript is designed to define behaviors and functionalities within zepeto world, including movement, physics, and interactions of objects handling events, including user inputs inherits from the zepetoscriptbehaviour class, designed to be compatible with unity's monobehaviour interface it can be attached to active gameobjects in the scene for execution ❗️ caution when developing for zepeto world, c# scripts are not included in the package build make sure to only implement using zepetoscript hello world tutorial step 1 creating a zepetoscript to create a new zepetoscript file, click \[project] and select the \[+] icon in the top left corner of the panel, or click assets → create → zepeto → typescript you can see that a new zepetoscript has been created, as shown below step 2 adding zepetoscript to a gameobject to add the previously created zepetoscript as a component to a gameobject, click the add component button in the inspector window of the gameobject in the add component window, select zepeto script component click the attach zepeto script button in the zepeto script component in the attach zepeto script window, select the helloworld zepetoscript file you created earlier you can add the helloworld zepetoscript file as a component to the gameobject as shown in the screen below step 3 adding test codes or emitting logs the newly generated zepetoscript is shown below you can edit the script using unity’s development tools newtypescript import { zepetoscriptbehaviour } from 'zepeto script'; export default class newtypescript extends zepetoscriptbehaviour { start() { } } try adding log codes within the start function to test whether the zepetoscript moves helloworld import { zepetoscriptbehaviour } from 'zepeto script'; export default class helloworld extends zepetoscriptbehaviour { start() { console log(`log hello world`); console warn(`warn hello world`); console error(`error hello world`); } } check out the test code output screen below congratulations on completing the zepetoscript tutorial! for those who have previously developed with c# in unity or those new to zepeto world development, let's dive into the basics of zepetoscript declaring variables in zepetoscript zepetoscript follows typescript syntax therefore, it is essential to declare the type when declaring a variable example of variable declaration typescript import { zepetoscriptbehaviour } from 'zepeto script'; export default class hellozepetoscript extends zepetoscriptbehaviour { // global variables private number number = 10; private floatnumber number = 10 5; private word string = "zepeto!"; private istrue boolean = true; private list number\[] = \[1,2,3]; private listgeneric array\<number> = \[4,5,6]; start() { console log(this number); console log(this floatnumber); console log(`hello, ${this word}`); console log(this istrue); console log(this list); console log(this listgeneric); // local variables let a = 30; const b = 40; console log(a); console log(b); } } using map data type instead of c#'s dictionary data type, use typescript's map data type to store and manage key value pairs this data type is especially convenient for managing player data when implementing a multiplayer world simple usage example of map typescript import { zepetoscriptbehaviour } from 'zepeto script'; export default class hellozepetoscript extends zepetoscriptbehaviour { private mymap = new map\<string, string>(); start() { this mymap set("player1", "ze"); this mymap set("player2", "pe"); this mymap set("player3", "to"); this mymap foreach((value, key) => { console log(key, value); }); if(this mymap has("player2")) { let value string | undefined = this mymap get("player2"); console log(value); } this mymap delete("player2"); console log(this mymap has("player2")); } } utilizing json when working with json formatted data, you can use typescript's built in functions converting a json string to an object use the json parse() method converting an object to a json string use the json stringify() method example of utilizing json typescript import { zepetoscriptbehaviour } from 'zepeto script'; export default class hellozepetoscript extends zepetoscriptbehaviour { start() { let jsondata = '{"id" "user1234", "name" "zepeto", "age" 15}'; // converting a json string to an object let userobject user = json parse(jsondata); console log(userobject id); console log(userobject name); console log(userobject age); userobject age = 16; // converting an object to a json string let newjsondata = json stringify(userobject); console log(newjsondata); } } class user { constructor(public id string, public name string, public age number) {} } for more detailed syntax, please refer to the typescript docs https //www typescriptlang org/docs/ https //www typescriptlang org/docs/