> cat /wizhelp/wizcoding6
========================================================================
MUD Coding Tutorial - Part 6
========================================================================
Debugging and troubleshooting your code.
DEBUG LOG:
Your debug.log in /lib/wizrooms/<yourname>/ shows errors.
```python
import logging
log = logging.getLogger(__name__)
def load():
log.info("Loading my room...")
try:
room = Room(...)
log.info("Room created successfully")
return room
except Exception as e:
log.error(f"Failed: {e}")
return None
```
COMMON ERRORS:
1. Missing imports:
```python
# WRONG:
room = Room(...) # NameError
# RIGHT:
from lib.models.entity import Room
room = Room(...)
```
2. No load() function:
```python
# WRONG:
room = Room(...) # Never loads
# RIGHT:
def load():
room = Room(...)
return room
```
3. Bad room names:
```python
# WRONG:
name="my room" # Spaces break goto
# RIGHT:
name="my_room" # Use underscores
```
4. Missing destinations:
```python
# Check exit destinations exist
exit = Exit("north", "fake_room") # Error!
# Verify first:
if "target_room" in game_state.rooms:
exit = Exit("north", "target_room")
```
TESTING CHECKLIST:
□ File loads without errors
□ goto to your room works
□ All exits lead somewhere valid
□ Items clone properly
□ Special features work
□ No crashes on bad input
DEBUG COMMANDS:
```python
# Test room
player.message(f"Room name: {room.name}")
player.message(f"Exits: {[e.name for e in room.exits]}")
player.message(f"Items: {room.inventory.count()}")
# Test state
player.message(f"Has sword: {player.has_item('sword')}")
player.message(f"HP: {player.current_hp}/{player.max_hp}")
```
PERFORMANCE:
```python
# BAD - Searches every time
for p in game_state.list_players():
if p.name == target:
...
# GOOD - Use built-in
player = game_state.find_player(target)
```
GETTING HELP:
1. Check debug.log first
2. Test with simple version
3. Look at working examples
4. Ask other wizards
Continue with help wizcoding7
========================================================================
>
_