getAreaRooms does not return all area rooms
fidel-perez opened this issue · 2 comments
Brief summary of issue / Description of requested feature:
getAreaRooms does not return all area rooms
Steps to reproduce the issue / Reasons for adding feature:
Using the code:
function customGetAreaRooms(area_id)
local room_ids = {}
for id,name in pairs(getRooms()) do
if getRoomArea(id) == area_id then
if string.match(name, "Jill") then
cecho("<white>\n".. tostring(getRoomArea(id)) .. "|" .. getRoomName(id))
end
end
end
end
customGetAreaRooms(212)
I get the result:
212|The Lair of Queen Jill
If I run the code:
function customGetAreaRooms2(area_id)
local room_ids = {}
for id,name in pairs(getAreaRooms(area_id)) do
if getRoomArea(id) == area_id then
if string.match(name, "Jill") then
cecho("<white>\n".. tostring(getRoomArea(id)) .. "|" .. getRoomName(id))
end
end
end
end
customGetAreaRooms(212)
I would expect the same result, but this returns nothing instead.
Error output / Expected result of feature
getAreaRooms should get all the rooms in an area.
After I replaced my code from getAreaRooms into customGetAreaRooms, it worked as expected.
Extra information, such as the Mudlet version, operating system and ideas for how to solve / implement:
I dont think this matters in this issue.
Still, I am using a this branch in Mudlet linux.
autosave.zip
I am attaching the DB file that has this issue for easier testing (and possibly be included into the unit tests of the fix).
The problematic area ID is 212, the room name is "The Lair of Queen Jill"
RTFM 🧙♂️
getAreaRooms(areaID)
returns a (lua "list"-type) table containing the rooms that are in that area. As such the id
inside the for
loop for the customGetAreaRooms2(...)
case is the (numeric) index (a number from {in this particular function} 0
{instead of the normal 1
because a C++ coder made a mistake in the dim and distant past and we don't want to fix it to start at 1
, as it should, as that could break things for scripts that already exist which handle that mistake} to one less than the total number of rooms in the area) whilst name
will contain the roomID number of the room concerned.
As a (bit pointless IMHO) proof of this try:
function customGetAreaRooms2(area_id)
for _, id in pairs(getAreaRooms(area_id)) do
if getRoomArea(id) == area_id then
if string.match(name, "Jill") then
-- you've already proved that getRoomArea(id) == area_id so there is no need to call getRoomArea(...) again
cecho("<white>\n".. area_id .. "|" .. getRoomName(id))
end
end
end
end
customGetAreaRooms(212)
I'm guessing that there is only one room in that area - as this is going to list all of them - honest!