How to start coding

How to start coding

Integrating with a code editor

You need a code editor, such as Visual Studio Code, to write and edit your script. This document takes Visual Studio Code as an example.

  1. Download Visual Studio Code.
  2. Specify the external code editor as Visual Studio Code in Studio Preference.

  1. Find Code in the folder where the Visual Studio Code is located and open it. Now Studio is integrated with the code editor.

Creating or adding scripts

  1. Open any space in YAHAHA Desktop.
  2. In the scene, choose the object that you want to write scripts for and click the More button on the upper right corner.
  3. Go to the Gameplay tab and click the drop-down arrow on the +Component button. You can either upload your local script by choosing Upload local script or create a script from scratch by choosing Add Script.

  1. Click the edit button to edit your script in your code editor.

Installing the YAHAHA Lua debugger

  1. Download the debugger
  2. Install the VS Code debugger by choosing … > Install from VSIX and opening the VSIX file you you just downloaded.

Configuring the YAHAHA Lua debugger

  1. Open the folder where the lua scripts are located.
  2. Create a launch.json file in Run and Debug.

  1. Copy the following JSON over to the file you just created.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ```
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: Debugging in Visual Studio Code
“version”: “0.2.0”,
“configurations”: [
{
“type”: “yahaha_lua_mobdebug”,
“request”: “attach”,
“name”: “Yahaha Lua Debugger”,
“basedir”: “${workspaceFolder}”,
“host”: “127.0.0.1”,
“port”: 8172,
“lua-extension”: [
“.lua”,
“.lua.txt”,
“.lua.bytes”
]
}
]
}

  1. Run the debugger to connect to YAHAHA Studio.

  1. Now you’ve successfully run the debugger and try to set a breakpoint in your script. YAHAHA Studio will connect to the debugger in Play mode.

1 Like