MudEngine Part 8: Inventory & Chat
Run it!
Start the fullstack dev server. The server loads game.toml with the new items fields.
dx serve --openOpen two browser tabs side by side:
Tab 1 โ Alice
- Enter name: Alice
- Click Enter the World โ Alice spawns in Town Square
- The room items list shows "loaf of bread" under "๐ฆ Items here"
- Type
take loaf of breadin the command input and press Enter - The item disappears from the room list and appears in Alice's inventory panel
- The floating player list shows Alice carrying "loaf of bread"
- A system message appears in chat: "โก Alice picks up loaf of bread."
Tab 2 โ Bob
- Enter name: Bob
- Bob spawns in Town Square and sees "loaf of bread" is gone
- Bob's floating player list shows Alice's inventory item
- Bob sees the system message about Alice taking the bread
Chat
- Alice types
say hello Bob!and presses Enter - Bob's chat panel shows: "Alice: hello Bob!"
- Alice's chat panel also shows the same message
Chat is room-scoped
- Alice walks north to Hilltop
- Both tabs show the move. Alice is in Hilltop, Bob is in Town Square
- Alice types
say Can you hear me? - Alice sees her own message
- Bob does not see the message โ he's in a different room
Drop items
- Bob walks north to Hilltop to meet Alice
- Bob types
drop breadโ but Bob doesn't have the bread, nothing happens - Alice types
drop loaf of bread - "loaf of bread" reappears in Hilltop's room items
- Alice's inventory is empty
- Both see the system message
Inventory edge cases
- Alice takes the bread again
- Bob tries
take loaf of breadโ fails (Alice already has it) - Alice walks south to Town Square while carrying the bread
- Alice drops the bread โ it appears in Town Square, not Hilltop
- Bob walks back to Town Square and takes it โ succeeds
Persistence โ items survive server restarts
- Alice picks up the "loaf of bread" from Town Square
- Close Alice's tab โ a system message shows: "โก Alice drops loaf of bread." The bread is back in Town Square
- Refresh Bob's tab โ Bob reconnects and the bread is in Town Square where Alice dropped it
- Open
game.tomlโ the file now has an empty[[players]]section (Alice disconnected) and her items were returned to the room they were in
Disconnect drops all items
- Alice takes "loaf of bread" and walks to Hilltop
- Alice closes her browser tab
- Bob sees: "โก Alice drops loaf of bread." โ the bread appears in Hilltop (Alice's last room), not in Town Square
- Bob walks to Hilltop and takes the bread โ it works
Items are persisted in game.toml
Open game.toml after taking and dropping items. Each room's items list reflects the current state:
- When you
takean item, it's removed from the room'sitemslist and added to the player'sitems - When you
dropan item, it's removed from the player and added back to the room - When a player disconnects, all their items are dropped into their current room
Stop the server with Ctrl+C and restart it โ items are still in their last known locations in game.toml.
The floating player list always shows every connected player, their current room, and the items they carry. It never scrolls away because it's fixed to the viewport.
"field items is missing" compiler error on serde derives
โ You added items to TomlRoom and TomlPlayer but not to the runtime types (PlayerInfo, RoomInfo, RoomData). Every struct that mirrors the TOML data needs the field.
"cannot find type ChatMessage"
โ Add the helper struct: #[derive(Clone, Debug)] struct ChatMessage { from: String, message: String, room: usize, is_mine: bool }. It goes just before the Game component.
Chat messages appear for everyone regardless of room
โ Check the Chat message receive handler. The client should filter using msg.room == my_room. If you're not tracking room in the ChatMessage struct, add the field.
Item doesn't appear in inventory after taking
โ The ItemTaken handler on the client pushes the item to the player entry in the players signal. Verify the handler matches the player_id field from the broadcast. Also check that the server's Take handler adds the item to player.items before broadcasting.
"my_info" is moved when used inside the for msg loop
โ The my_info value is computed from signals outside the rsx! block. In the chat rendering section, we call my_info.as_ref() inside the for loop body rather than capturing the outer value by reference. The pattern shown in the code (let is_same_room = my_info.as_ref().map_or(...)) avoids ownership issues because it reads from the signal each time.
Floating player list overlaps the grid
โ Ensure .game-layout { margin-right: 250px } is in your CSS. Adjust the value if your panel or margin is different.
Command input does nothing on Enter
โ Check that onkeydown uses Key::Enter (not "Enter" string). In Dioxus 0.7, key events return the Key enum, not a string.