To get a believable plate number without asking the player to type one, you may want to generate the license plate text by following a specific pattern.
The settings for generating the text are located in the vars.plate block.
This example will generate text like BNG-042:
"vars": {
"plate": {
"type": "string",
"default": "BNG-{d}{d}{d}",
"charsets": {
"d": "0123456789"
},
"maxLength": 8
}
}
Anything outside braces is copied as-is. Anything inside braces is a token. In this example, {d} means “pick one character from the d charset”.
You can choose your own token names:
"default": "{letter}{letter}-{number}{number}{number}",
"charsets": {
"letter": "ABCDEFGHJKLMNPQRSTUVWXYZ",
"number": "0123456789"
}
A charset can also be a list of full strings. That is useful for regions, prefixes, or short words:
"default": "{region}-{d}{d}{d}",
"charsets": {
"region": ["N", "S", "E", "W"],
"d": "0123456789"
}
default can be a list. The game will pick one pattern when it generates a plate:
"default": [
"{letter}{letter}-{d}{d}{d}",
"{d}{d}-{letter}{letter}{letter}"
]
If you repeat an entry, it becomes more likely because the game chooses one item from the list:
"default": [
"{letter}{letter}-{d}{d}{d}",
"{letter}{letter}-{d}{d}{d}",
"{d}{d}-{letter}{letter}{letter}"
]
Sometimes the wide and square plate formats need different generated text. Put a formats block inside vars.plate:
"vars": {
"plate": {
"type": "string",
"default": "{letter}{letter}-{d}{d}{d}",
"formats": {
"30-15": {
"default": "{letter}{letter}\n{d}{d}{d}"
}
},
"charsets": {
"letter": "ABCDEFGHJKLMNPQRSTUVWXYZ",
"d": "0123456789"
},
"maxLength": 8
}
}
The format-specific pattern is used only when that plate format is being rendered.
Players can type their own plate text. Use minLength and maxLength to describe what your design expects:
"minLength": 0,
"maxLength": 8
Keep maxLength realistic for your layout. A text node with "fit": "shrink" can prevent overflow, but very long plate text will still look cramped.
You can define extra variables with a preset list. The game picks one entry based on the plate text and keeps that choice stable for the same text:
"vars": {
"plate": {
"type": "string",
"default": "{letter}{letter}-{d}{d}{d}",
"charsets": {
"letter": "ABCDEFGHJKLMNPQRSTUVWXYZ",
"d": "0123456789"
}
},
"stickerColor": {
"preset": ["#2b6cff", "#24a148", "#f1c21b"]
}
}
You can then use {stickerColor} in a node, for example as the color of a small box.
The template automatically provides {plate}. Some layouts need more than one text node.
For a two-line plate, use limit and limit2 on the format:
"30-15": {
"size": [512, 256],
"limit": 3,
"limit2": 5,
"root": {
"children": [
{ "type": "text", "text": "{line1}" },
{ "type": "text", "text": "{line2}" }
]
}
}
line1 gets the first limit characters. line2 gets the next limit2 characters.
For more precise splits, use segments. Ranges are zero-based, and the end is not included:
"segments": [[0, 2], [2, 5], [5, 8]]
This creates {seg1}, {seg2}, and {seg3}.
Was this article helpful?