← Writeups
Kregs ToolboxJune 13, 2026

Building a Beginner Friendly Scripting System

Overview

For my GAM300/350 classes at DigiPen, I was the UI/UX programmer on a team of eight Computer Science majors. Over two semesters we built a custom 3D C++ game engine and a game with it. The engine was very big with a Vulkan renderer, a custom audio mixer, Jolt physics, and our own scripting language, Prose.

The game took inspiration from Kodu Game Lab, Project Spark, and Dreams, so players needed to be able to write game logic without knowing how to write code. Our Systems programmer built the Prose language and compiler. I integrated the Clay UI library into the engine and built a drag-and-drop block editor that generates Prose code. Our Graphics programmer, with a little help from me, wrote the system that turns Clay's render commands into Vulkan draw calls.

This writeup will cover the editor; the panels, the blocks, and how drag-and-drop works with the immediate mode rendering.


The Editor Layout

The scripting editor is a two-panel view that opens when you select a script file from the properties panel.

My original mockup of the editor

Left panel, the block sidebar

  • Lists all available block categories (Events, Objects, Whiteboard, Functions, Math, Movement, Logic, Text, Audio)
  • Each category is a collapsible accordion section; clicking a header toggles it open/closed
  • Each category has its own color scheme defined in its JSON file, so blocks are visually grouped by type at a glance
  • Blocks shown in the sidebar are templates, they stay put when you drag one out but are used to create the actual block

NOTE: The "Whiteboard" was our solution to variables, a per-object key value storage.

Right panel, the sentence canvas

  • Scrollable list of sentences (the top-level scripting unit)
  • Each sentence has a WHEN section and a THEN section
  • A green "Add New Sentence" button lives at the bottom

A screenshot of the block scripting editor


Sentences

A sentence is the basic logical unit in Prose: WHEN [conditions] THEN [actions].

// Generated Prose Code, line 3 in above screenshot
sentence Sentence3:
{
	events: told("take_damage");
	when:
	{
		return ((wbget(self, "lives") < 1) and (wbget(self, "immunity_timer") < 0));
	}
	then:
	{
		tell(self, "die");
	}
}
  • Conditions and actions are separate ordered lists of blocks
  • Between every block (and at each end) there is an invisible drop zone that lets you insert a block at any position, not just at the ends

The damage handling sentence in the editor

A trash icon sits to the left of each sentence to delete it entirely. Dropping any non-sidebar block back onto the sidebar also deletes it.


Blocks

Blocks are the draggable pieces. Every block is a horizontal strip of content. It contains a mix of static text labels and interactive input slots.

The mockup for the structure of a block

Each block has:

  • Category - which group it belongs to (sets its color and sidebar location)
  • Placement rules - whether it can go in CONDITION or ACTION (WHEN or THEN), and whether it's an outer or inner block
  • Content - an ordered list of text and input pieces that make up its visual label, each content can also contain an inner block instead
  • A unique ID - used to track and move it when dragging

Blocks are defined entirely in JSON files under res/Scripting/blocks/. Adding a new block means adding an entry to the right category file.

{
    "category": {
        "id": "wb",
        "name": "Whiteboard",
        "description": "Use these blocks to directly interact with the values in an object's whiteboard",
        "color": {
            "text": [ 255, 255, 255 ],
            "bg":   [ 139, 92, 246]
        }
    },
    "blocks": {
        "wbset": {
            "name": "Set",
            "description": "Set the value of a variable on the whiteboard of this object.",
            "argument": false,
            "placement_restrictions": {},
            "content": [
                {
                    "type": "STRING",
                    "label": "variable",
                    "id": 1
                },
                {
                    "type": "TEXT",
                    "text": "to"
                },
                {
                    "type": "ANY",
                    "label": "value",
                    "id": 2
                }
            ],
            "output": "wbset(self, $1, $2)"
        }
    }
}

Inner vs Outer blocks

  • Outer blocks live directly in a sentence's condition or action row
  • Inner blocks can be nested inside another block's input slot, replacing the default text/number field with a computed value

Input Slots

Input slots are the interactive pieces embedded inside a block. Each slot has a type:

Type Widget Example
String Text field A dialog line
Number Text field A distance value
Enum Dropdown Direction (Left/Right/Up/Down)
Variable Dropdown A named whiteboard variable
Object Reference Dropdown A prefab to spawn
SFX / Music Dropdown An audio asset
Entity Reference Block slot only A live entity
Boolean Block slot only True/False

Dropdown inputs populate their options from the project registry at runtime, so the list of variables or audio assets updates automatically as the project changes.

An input slot can also accept an inner block as its value instead of a typed input. The slot becomes a drop zone and the nested block's output is used in its place. Entity reference and boolean slots have no widget of their own. They exist just to hold an inner block that produces the value, like a comparison block for a boolean.


Drag and Drop

Fighting With Immediate Mode

Clay is an immediate-mode library, so every frame you declare the whole UI from scratch, Clay lays it out, and nothing carries over to the next frame. Drag-and-drop is the exact opposite, it's state that needs to persist across multiple frames, like what's being held, where it came from, and what it's hovering over. That disconnect is what I fought with the most often.

My solution was to keep the editor as a retained tree of my own objects and have Clay only describe it each frame. Sentences own BaseBlocks, blocks own their content, and every block and drop zone owns its drag-and-drop handle. Three key design points made that work out.

Stable IDs from persistent UIDs. Each block declares its Clay element with an ID derived from its own UID rather than its position in the list:

this->m_draggableHandle->m_elementID = CLAY_IDI("block", this->m_uid);

The reason is hit testing. During declaration, the only layout Clay can report is the one from the previous frame, so Draggable and Droppable test the mouse against Clay_GetElementData(id).boundingBox. If IDs came from list positions inserting a block would shift every ID after it (which was my initial solution, this happened a lot), and hit tests would use other blocks' boxes for a frame. Keying on UID means a block always finds its own box, wherever it moved.

Dragging without leaving the tree. A held block isn't removed from its sentence while you drag it. It's drawn in the same place in the tree, but switched to a Clay floating element: it's taken out of the layout flow, offset by the drag, and given a raised z-index. The data only changes on drop, so a cancelled doesn't need to undo anything.

Drop zones updated every frame. Drop zones sit between blocks, so the amount of them depends on the data. Before drawing, each sentence calls CheckDropCount() which adds or removes Droppables until there is one more than there are blocks in each row. This keeps the drop zones in sync with the block list which may change on any frame.

The Pieces

The DND system has three parts: Draggable, Droppable, and DNDManager.

Draggable is attached to every block. It tracks:

  • The block's last known bounding box (so it knows where it started)
  • A click offset (so the block doesn't snap to your cursor's top-left)
  • A z-index (bumped on pick-up so the dragged block renders above everything)
  • An opaque data payload (std::any) carrying the block's ID and whether it came from the sidebar

Droppable is attached to every drop zone. It tracks:

  • Which Draggable was released over it (cleared each frame after handling)
  • Whether something is currently hovering over it (for visual feedback)

DNDManager is the coordinator. There is one per editor. It:

  • Holds a pointer to the currently-dragged block
  • Wraps the entire editor's draw call so it can render the floating drag preview on top of everything
  • Is registered as a global singleton so any droppable can report back to it

What happens on drop

  1. The Droppable fires with a pointer to the released Draggable
  2. The sentence checks the draggable's data payload
  3. Sidebar block → a new block is constructed from the template JSON and inserted at the drop index
  4. Canvas block → the block is located by UID anywhere in the loaded sentences (including nested), moved out of its current position, and inserted at the new index
  5. The script is auto-saved to JSON after every drop

Save and Load

The editor saves each script as two files:

  • A .json file storing the block tree (which blocks, in which order, with what input values)
  • A .prose file, the compiled text output that the runtime reads

Saving happens automatically on every block drop and explicitly when you hit the Back button. The Back button also triggers a recompile of the .prose file and returns you to the properties panel. The JSON save format mirrors the block tree exactly, so loading is just reconstructing blocks from their category+id template and re-filling the saved input values.


Looking Back

Before building the in-engine editor, I built a web prototype to playtest the block scripting idea on its own. It gives players a few scenarios to solve, like opening a door or collecting coins, plus a sandbox. Playtesters had a lot of fun with it, and some even asked if they could keep playing with it. The in-engine version got a lot less outside testing, but a few teammates used it for work in the engine. Once I'd fixed some of the usability and quality-of-life issues they found, it held up decently well.

As a project, we spent the whole year torn between making impressive tech for our portfolios and making a cohesive game. The final game showed that tension. Still, each of us came out of it with a system worth showing, and this editor is mine.

Kregs Toolbox logo

Related Project

Kregs Toolbox

A beginner-friendly game creation tool built on a custom C++ engine. I built its Scratch-style editor, which compiles drag-and-drop blocks into our own scripting language

→