Tables: On-Chain Data
Primodium tables are smart contracts that store on-chain data. Primodium tables are based on on-chain tables (opens in a new tab) as defined in the open MUD standard.
There are two main types of on-chain tables used in Primodium.
Prototype Tables
Prototype tables store game configuration data such as building costs, unit
stats, and other game constants. These tables are used to define the game's
rules and are not expected to change during the game's lifecycle. Prototype
tables are prefixed with P_
and are populated during the PostDeploy
step.
The following json string in
mud.config.ts
(opens in a new tab)
encodes a table that stores key game configuration named P_GameConfig
.
{
// ...
P_GameConfig: {
key: [],
schema: {
admin: "address",
unitProductionRate: "uint256",
travelTime: "uint256",
worldSpeed: "uint256",
maxAsteroidsPerPlayer: "uint256",
asteroidChanceInv: "uint256",
asteroidDistance: "uint256",
unitDeathLimit: "uint256",
},
},
// ...
}
Tables
All other tables store in-game data associated with players, space rocks,
alliances, and other game entities. These tables are expected to change during
the game's lifecycle. The following json string encodes a table that stores the
position of a building named
Position
(opens in a new tab).
{
Position: {
key: ["entity"],
schema: {
entity: "bytes32",
x: "int32", y: "int32",
parentEntity: "bytes32"
},
},
}
Reading and Writing Tables
Tables can be read directly from their contracts via their ABIs. See the MUD documentation on the table data model (opens in a new tab) for more information on how tables are structured on-chain.
Both prototype and player tables cannot be written directly without systems unless delegated.