From 6b1a475ed461a14c4fa9cd3236a57ec2d28b3112 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Sun, 9 Mar 2025 10:30:26 +0800 Subject: chore: better error response with room connection --- objects/room.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'objects/room.lua') 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 -- cgit v1.2.3