Data-driven content: designers edit data, not code

Turn Beacon Yard's flat Config constants into items and enemies as JSON data: Rojo JSON modules, kinds in code and rows in data, a validator with design rules that fails CI through Lune, a generated ItemId type, and where Experience Configs fit.

Lab lesson, about 75 minutes, 10 steps

By the end you can

  • Separate content (rows of data) from behaviour (code that handles each kind of row)
  • Move Beacon Yard's items and enemies into JSON files that Rojo turns into modules
  • Write a validator that reports every broken row and runs in CI through a Lune script
  • Generate Luau types from the data so a typo in an item id fails the type check

Before this: One source of truth: replicated state, Core loop design: act, reward, spend, repeat, Continuous integration: every check, blocking

Step 1 of 10

A repair kit, and the seven files it touches

Beacon Yard keeps every gameplay number in one module, which was the right first step:

	SPEED_PRICE = 25,
	SHIELD_PRICE = 40,
	COIN_PACK_COINS = 50,

But numbers are only part of an item. The shop service knows each item by name, in code:

function ShopService.purchase(player: Player, item: unknown)
	if item == "Speed" then
		buySpeed(player)
		return
	end
	if item == "Shield" then
		buyShield(player)
		return
	end
	if item == "CoinPack" then
		MonetizationService.prompt(player)
		return
	end
	if item == "SpeedPass" then
		PassService.prompt(player)
Work it out

Search src/ at m14-ship for every file that mentions the Shield item (its price constant, the string "Shield" or its label key). A repair kit built the same way would touch the same files. How many are there?

files

Link to this step · This confused me

Step 2 of 10

Rows in data, kinds in code

The split is simple to say: data lists the things, code handles each kind of thing. An item row says { id = "RepairKit", kind = "consumable", price = 30, currency = "Coins", labelKey = "shop.repair" }. The shop service has one function per kind: an upgrade is bought once and kept, a consumable is bought and used up, a pass or pack opens a Robux purchase. A row can reuse a kind handler. At m15-scale the buttons are still written by hand and coin items use effects keyed by id. The upkeep and rebuild kinds arrive at m16-design-pass.

Stored dataContent as data, behaviour as code is a restaurant's menu board that the manager edits, a kitchen that knows the techniques, and a head chef who checks each new line.
In the pictureIn Roblox
A line on the menu boardA row in items.json: id, kind, price, currency, labelKey
A cooking technique the kitchen knowsA kind the code handles: upgrade, consumable, pass, pack
A dish that needs a technique the kitchen lacksNew behaviour, such as a dash, that needs code first
The head chef checking a new line before it goes upContentRules.validate running in CI on every pull request

See the whole analogy cast

Think of a restaurant. The menu board lists dishes with prices, and the manager can add a dish or change a price with a marker. The kitchen knows techniques: grill, fry, bake. A new dish that is grilled goes straight on the board. A dish that needs a technique the kitchen does not have yet, say smoking, needs the kitchen to change first. And before a new line goes up, the head chef checks it: is there a price, do we have the ingredients?

Think of it as A restaurant's menu board that the manager edits, a kitchen that knows the techniques, and a head chef who checks each new line

Choose one

Which of these changes needs only an item data edit at m15-scale?

Which of these changes needs only an item data edit at m15-scale?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 3 of 10

JSON files that Rojo turns into modules

Where does the data live? Rojo syncs any .json file that is not a model, project or meta file as a ModuleScript that returns the same structure as a table1. So src/shared/data/items.json:

json
{
  "items": [
    { "id": "Speed", "kind": "upgrade", "price": 25, "currency": "Coins", "labelKey": "shop.speed" },
    { "id": "Shield", "kind": "consumable", "price": 40, "currency": "Coins", "labelKey": "shop.shield" },
    { "id": "CoinPack", "kind": "pack", "currency": "Robux", "productKey": "COIN_PACK", "labelKey": "shop.pack" },
    { "id": "SpeedPass", "kind": "pass", "currency": "Robux", "productKey": "SPEED_PASS", "labelKey": "shop.pass" }
  ]
}

becomes a ModuleScript at ReplicatedStorage.Shared.data.items, and require returns a table with an items array, on the server and the client alike. Robux items have no price: the Creator Hub owns Robux prices, and a second copy here would drift. They name the id key in Ids.luau instead. enemies.json holds the drone and crawler stats the same way. Both live in src/shared/data/ alongside rewards.json and zones.json. Only items and enemies wrap their rows inside a named object field.

Predict the output

With items.json synced by Rojo as above, what does this print in Studio?

local data = require(game.ReplicatedStorage.Shared.data.items)
print(#data.items, data.items[2].id, data.items[3].price)
With items.json synced by Rojo as above, what does this print in Studio?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 4 of 10

A validator that names every broken row

JSON accepts anything that parses. "price": -30, a typo in a label key, a kind nobody handles: all valid JSON. The validator is the head chef. It reads every row and reports every problem with the file, the row number, the id and the field, so a designer can fix them all in one go:

Luau
Ctrl Enter runs the cell. Checked against the expected output

Validators can hold design rules too, not just shape. With WRENCH_DAMAGE = 34, the crawler's 68 health takes 2 hits and the drone's 100 takes 3. A rule such as "no enemy needs more than six wrench hits" stops a designer from shipping a 250-health drone that nobody can finish before the drill ends, and the rule lives next to the data instead of in someone's head.

Work it out

With a wrench of 34 damage and a limit of six hits, what is the highest maxHealth the validator accepts?

health

Link to this step · This confused me

Step 5 of 10

Run the rules on every pull request

A rule that only runs when someone remembers is not a rule. Keep the rules in one pure Luau module, src/shared/ContentRules.luau, with no Roblox calls, so three places can run the same code:

  1. CI, through a Lune script. scripts/check-data.luau reads the JSON files with @lune/fs, decodes them with serde.decode("json", text) from @lune/serde, requires the rules with a relative path such as require("../src/shared/ContentRules"), prints each error and exits with code 1 when there are any23. A data job in .github/workflows/ci.yml runs lune run scripts/check-data, next to the existing check-ids and check-challenges jobs.
  2. The game, when Config loads. If items or enemies are broken, Config raises an error and refuses to load, on every server, so a broken row that skipped CI cannot reach players.
  3. A designer's plugin, which Tools for your team: plugins, CLIs and code generation builds. The plugin edits zones, so it runs the per-file schema described next, not ContentRules.

ContentRules holds the cross-file design rules for items and enemies, such as "the wrench kills this enemy in at most six hits". Its partner is src/shared/ContentSchema.luau, a per-file schema for every other data file (rewards.json, zones.json): each row needs a unique id, and each field has a type and limits. The same schema also writes the row types into GeneratedTypes.luau, so code that reads a row gets a real type for it.

Shared rules, three places that run themA gold box labelled Data files points down to an ink box labelled ContentRules and ContentSchema. That box points down to three boxes: a copper box CI with lune run, a copper box Config that refuses to load, and a cyan box Plugin that runs ContentSchema for zones.checked byData filesitems, enemiesRules + Schemapure LuauCIlune runConfig loaderror()PluginContentSchema
Write the rules once; every place that can change the data runs them.
Choose one

Why keep the rules in one module with no Roblox calls, instead of writing the CI check in JavaScript like check-ids.mjs?

Why keep the rules in one module with no Roblox calls, instead of writing the CI check in JavaScript like check-ids.mjs?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 6 of 10

Generate types from the data

Code still names items: ShopApp declares export type ShopItem = "Speed" | "Shield" | "CoinPack" | "SpeedPass" by hand. With items in data, that line is a copy that will drift. Generate it instead:

Luau
Ctrl Enter runs the cell. Checked against the expected output

The Lune script writes that line into src/shared/GeneratedTypes.luau with a header saying the file is generated. Code that accepts ItemId can catch typos in scripts/typecheck.sh. ShopService.purchase takes unknown because it receives a remote argument, so it still checks the item id at runtime. Beacon Yard already generates files, in scripts/gen-assets.mjs, which builds account-bound models from templates and your ids; this follows the same pattern.

Choose one

The generated file is committed. What should CI do about it?

The generated file is committed. What should CI do about it?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 7 of 10

Data files or live configs?

Data files ship with a deploy. Some values must change without one: the Scrap Rush multiplier that FlagService reads from an Experience Config changes in running servers, no restart4. Use each for what it is good at:

  • Data files: what exists. Items, enemies, labels, rewards and zones. Reviewed in a pull request, validated in CI, shipped with code that knows their kinds.
  • Experience Configs: knobs on what exists. Event multipliers, a price for a weekend, a kill switch. Changed live, always clamped by limits in code, as EVENT_MAX_MULTIPLIER clamps the event today.

Where content can live

OptionWhat it isWhen pros pick itTrade-offs
Luau tables in a ModuleScriptConfig.luau today: constants and tables written in Luau.Small games, programmer-tuned values.Designers edit code; no schema beyond the type checker.
JSON modules via RojoPlain .json files Rojo turns into ModuleScripts.Content that designers and scripts edit, validated in CI.No comments in JSON; every rule lives in the validator.
TOML modules via RojoRojo syncs .toml the same way; TOML allows comments.Hand-edited config that benefits from notes.Rojo turns TOML dates into strings; fewer tools than JSON.
Spreadsheet exportDesigners work in a sheet; a script converts CSV to JSON, then the same validator runs.Large tables tuned by non-programmers (economy, drops).One more conversion step to keep in CI.
Experience ConfigsValues set on the Creator Hub and read live by servers.Live-ops knobs and kill switches.Not for defining new content; always clamp in code.
Choose one

Marketing wants the Shield at 30 coins for this weekend only, starting tomorrow, without a new version. Where does that change go?

Marketing wants the Shield at 30 coins for this weekend only, starting tomorrow, without a new version. Where does that change go?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 8 of 10

Build along: items and enemies as data

You build this in your own copy of the finished game. First pass the level 3 challenge below, then copy challenges/work/content_rules.luau to src/shared/ContentRules.luau.

The data job fails a pull request and names the row and field to fix.

Build along

m14-ship to m15-scale

  • src/shared/data/items.json
  • src/shared/data/enemies.json
  • src/shared/data/rewards.json
  • src/shared/data/zones.json
  • src/shared/Content.luau
  • src/shared/Config.luau
  • src/shared/ContentRules.luau
  • src/shared/ContentSchema.luau
  • src/shared/GeneratedTypes.luau
  • scripts/check-data.luau
  • src/server/ShopService.luau
  • unit/specs/ContentSchema.spec.luau
  • .github/workflows/ci.yml
  1. Place the four JSON files in src/shared/data/. Wrap items and enemies in objects with named arrays. Read the rows through Content; Config reads item prices and enemy stats through it, and keeps numbers like WRENCH_DAMAGE.

    You should see ReplicatedStorage.Shared.data contains items, enemies, rewards and zones after a Rojo sync.

  2. Look up the id with Content.findItem. Dispatch via HANDLERS for upgrade, consumable, pass and pack. Keep the per-id coin effects and the hand-written shop buttons.

    You should see ShopService.purchase dispatches by the row kind.

  3. Run lune run scripts/check-data. The script checks item and enemy rows with ContentRules, using keys from src/locale/Strings.csv and wrench damage read from the text of Config.luau. It also runs ContentSchema.validateAll. Use --write to regenerate GeneratedTypes.luau.

    You should see The check reports four valid files and exits 0. A negative coin price fails the check.

  4. Use the data job in .github/workflows/ci.yml and unit/specs/ContentSchema.spec.luau as references. At this tag, the cross-row case checks the Yard boundary.

    You should see The data job runs the same check. The zone spec rejects a box outside the Yard.

Link to this step · This confused me

Step 9 of 10

Where the menu picture breaks

Choose one

A chef sees a strange menu line and asks the manager what it means. What does Beacon Yard's code do with a row whose kind is spelled "consumible"?

A chef sees a strange menu line and asks the manager what it means. What does Beacon Yard's code do with a row whose kind is spelled "consumible"?

Press 1 to 4 to choose, Enter to check.

Where does it break?“A restaurant's menu board that the manager edits, a kitchen that knows the techniques, and a head chef who checks each new line” is a good picture of content as data, behaviour as code. Where does it stop being true?

It breaks here. A chef can ask what a strange line means; code cannot, so every assumption it makes about the data has to be a validator rule. And a menu board is a few dozen lines read at a glance, while game data is hundreds of rows across files that refer to each other, which only the validator and generated types check.

The true model. Data lists the content and code handles each kind of content; a pure Luau validator checks shape, links and design rules everywhere the data can change, types generated from the data check the links from code, and Experience Configs tune shipped content live within limits.

There is a second break. A menu board has a few dozen lines a chef can read at a glance. Game data grows to hundreds of rows across many files that refer to each other: an item's label key must exist in the translations, a zone box must stay inside the Yard. The validator is what checks those links, and generated types are what check the links from code.

Link to this step · This confused me

Step 10 of 10

Challenges and recap

This validator never notices a duplicate id, so the second Drone row silently replaces the first wherever code looks rows up by id. Fix it so a repeated id is an error.

Luau
Ctrl Enter runs the cell. Checked by tests

Level 1, Apprentice

Challenge

Fix validate in the dup-fix cell.

Start from
The game at milestone m14 (download)
Check it here
Run the code cell; the challenge completes when it passes. No Studio needed.

Done means

  • validate remembers each id it has seen
  • A repeated id gives one error naming its row and the id field
  • All four assertions in dup-fix pass
Put in order

Put a designer's Repair Kit change in order once the build-along is done.

  1. CI's data job runs ContentRules on every row and checks the generated file is current
  2. Run lune run scripts/check-data --write to regenerate GeneratedTypes.luau
  3. Add a consumable row and a shop.repair line in Strings.csv
  4. Open a pull request
  5. After review and merge, add the kit's button and effect, then the deploy ships it

Level 2, Builder

Challenge

Prove the pipeline with a real item. There is no Luau test for this one: the proof is the failed and then passing pull request, and the kit in the shop.

Start from
The game at milestone m14 (download)

Done means

  • The build-along is done in your copy: items and enemies in JSON, ContentRules, check-data and the CI job
  • A Repair Kit row for 30 coins validates after you add its label and regenerate GeneratedTypes.luau
  • A test pull request with the price set to -30 fails the data job with a message naming RepairKit and price
  • The fixed pull request passes, and in Play the shop sells the kit

Meet the criteria above, then record your own result. No test grades this check.

Level 3, Professional

Challenge

Write validate, hitsToKill and itemIdType in challenges/work/content_rules.luau. The written solution is challenges/solutions/data-driven-content.md. In Play, run game.ServerScriptService.RunGameTests:Invoke("data-driven-content", "data-rules") and paste the pass code here.

Start from
The game at milestone m14 (download)
Grade it
In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("data-driven-content", "data-rules") in the server command bar. Copy the pass code from Output.

Done means

  • The real yard data passes with no errors
  • Each of fifteen broken rows gives exactly one error naming the row's id and the field
  • Several broken fields give one error each
  • hitsToKill rounds up, and an enemy that takes exactly six hits is allowed
  • itemIdType returns the export type line with quoted, sorted ids
  • challenges/data-driven-content.luau prints TEST PASS for every check

The Course Runner prints this code when the test passes.

Retiring the analogy

You no longer need “a restaurant's menu board that the manager edits, a kitchen that knows the techniques, and a head chef who checks each new line”. Data lists the content and code handles each kind of content; a pure Luau validator checks shape, links and design rules everywhere the data can change, types generated from the data check the links from code, and Experience Configs tune shipped content live within limits.

Recap

  1. At m14-ship one shop item touches seven files, all code but one, because items are known by name in code.
  2. Data lists the things; code handles each kind. A new row of a known kind needs no code in the shop service; buttons and effects are still hand-written at m15-scale.
  3. Rojo syncs a .json file as a ModuleScript that returns the table; missing fields read as nil.
  4. One pure ContentRules module checks items and enemies, reports every broken row by file, row, id and field, and runs in CI through Lune and when Config loads. ContentSchema checks every other file, and the zone plugin runs it too.
  5. Generate the ItemId type from the data, commit it, and have CI fail when it is stale.
  6. Data files define what exists and ship with a deploy; Experience Configs tune it live, always clamped in code.

Content as data, behaviour as code is a restaurant's menu board that the manager edits, a kitchen that knows the techniques, and a head chef who checks each new line, until a chef can ask what a strange line means; code cannot, so every assumption it makes about the data has to be a validator rule. And a menu board is a few dozen lines read at a glance, while game data is hundreds of rows across files that refer to each other, which only the validator and generated types check.

Next The network budget: measure, batch, pack

Link to this step · This confused me