Read and edit AI-generated code
The rules of a game made with AI GAME BUILDER live in script files. Reading the code yourself lets you check whether the AI's report is accurate, and changing a single number is faster by hand than asking the AI. This page walks through finding, reading and manually editing AI-generated scripts, then handing the work back to the AI.
Before you start
- How to open a script is in Code editor; the script format is in Scripting overview and the engine API.
- Create a checkpoint before you edit. Scripts are assets shared by the whole project, so a bad edit can break other scenes too (Save and restore your work with checkpoints).
1Find which script does what
- In HIERARCHY, entities with a
<>mark next to the name have scripts attached. - Select the entity and look at the SCRIPT component. It shows the attached scripts' names and attributes.
- Click the pencil icon on the script's name row to open the code editor. You can also select the script file in ASSETS to read and edit it right away in the CODE field on the right.
AI-generated scripts often include Korean // comment lines. Skimming the comments first gives you the structure quickly. Pending Check the share of comment lines in 3 AI games on the current version
2Reading order
- Attributes (
attributes.add): values exposed so you can change them. Speeds, counts and text are here. If you only want to change a number, don't edit the code; change it in the SCRIPT component (Change script attribute values). initialize: see what is set up and which events are connected when the game starts.update: see what is checked every frame. Input, time and end conditions are usually here.- Event functions: follow the functions connected with
on('collisionstart', …)andapp.on('…')(Events and communication between scripts).
3Ask the AI to explain
Ask the AI to explain the parts you don't understand. Always include "don't change anything." If you leave it out, the AI may edit the code while explaining it.
Explain how ballMove.js sets the ball's speed. Don't change the code.
4Edit by hand
- Find the line to change and edit it.
- Save: in the CODE field, click Save; in the code editor tab, choose File → Save File.
- Refresh the game tab to check.
If there's a syntax error, a red line appears in the browser Console of the game tab (Debugging).
5Hand it back to the AI
When you ask the AI for the next task after editing by hand, tell it what you changed. If you don't, the AI may revert your change. Pending Check whether the AI reverts manual edits in 3 requests
I changed the default speed in ballMove.js from 5 to 8. Keep that value as it is,
and only add a feature that shows "Clear" text when all the stars are collected. Don't touch anything else.