Skip to content

Commit

Permalink
docs(world): fix minor bugs in the world docs (#1115)
Browse files Browse the repository at this point in the history
Co-authored-by: alvarius <[email protected]>
  • Loading branch information
Hujunjob and alvrs authored Jul 31, 2023
1 parent 168a4cb commit 16d8c43
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions docs/pages/world/world-101.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,29 @@ Now we can import our new table, and write something to it. Let’s write a func
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { System } from "@latticexyz/world/src/System.sol";
import { Dog } from "../codegen/tables/Dog.sol"; // import table we created
import { Dog, DogData } from "../codegen/tables/Dog.sol"; // import table we created
contract MySystem is System {
function addEntry(string memory name, string memory color) public returns (bytes32) {
bytes32 key = bytes32(abi.encodePacked(block.number, msg.sender, gasleft())); // creating a random key for the record
address owner = _msgSender(); // IMPORTANT: always refer to the msg.sender using the _msgSender() function
Dog.set(key, {owner: owner, name: name, color: color}); // creating our record!
Dog.set(key, DogData({owner: owner, name: name, color: color})); // creating our record!
return key;
}
}
```

That’s it! `MySystem`, just like `IncrementSystem`, will have access to Dog given they are in the same namespace.


We can run `pnpm mud worldgen` in the contract folder to recreate the systems.

```bash
> pnpm mud worldgen
Generated system interface: src/codegen/world/IIncrementSystem.sol
Generated system interface: src/codegen/world/IMySystem.sol
Generated system interface: src/codegen/world/IWorld.sol
```

After this step, the filesystem of the World is like this:

```bash
Expand Down

0 comments on commit 16d8c43

Please sign in to comment.