diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-09 10:30:26 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-09 10:30:26 +0800 |
| commit | 6b1a475ed461a14c4fa9cd3236a57ec2d28b3112 (patch) | |
| tree | a7fc065562347aa04f20ca0aca57a7e825ff4d22 /objects/room.lua | |
| parent | 533542a892a172b53d519ae6ca152214ed756c12 (diff) | |
chore: better error response with room connection
Diffstat (limited to 'objects/room.lua')
| -rw-r--r-- | objects/room.lua | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/objects/room.lua b/objects/room.lua index 7982e9c..678d526 100644 --- a/objects/room.lua +++ b/objects/room.lua @@ -137,6 +137,10 @@ end -- control functions function Room:addDoor(door) + if self.doors[door.location] then + print("door location unavailable") + return false + end table.insert(self.doors, door) end @@ -183,8 +187,12 @@ function Room:connect(anotherRoom, way) -- connect room with determined direction local door1 = Door:new(directions[1], self, anotherRoom) local door2 = Door:new(directions[2], anotherRoom, self) - self:addDoor(door1) - anotherRoom:addDoor(door2) + + local doorResult1 = self:addDoor(door1) + local doorResult2 = anotherRoom:addDoor(door2) + if not doorResult1 or not doorResult2 then + return false + end return door1, door2 end |
