I've also been wrestling with this one. This is the rex pattern I'm using to attempt to get exits and details from the string in content which is a sample GMCP Room.Info string.
ROOM_INFO = rex.new ('\{ \"num\"\: (?<ID>\d+)\, \"name\"\: \"(?<name>.+)\"\, \"area\"\: \"(?<area>.+)\"\, \"environment\"\: \"(?<environment>.+)\"\, \"coords\"\: \"[0-9\,]\"\, \"map\"\: \"\.+\"\, \"exits\"\: \{ (\"(?<exit>\w+)\"\: (?<exitID>\d+)[,]?[ ]?)* \}, \"details\"\: [ ("(?<detail>\w+)\"[,]?[ ]?])* ] }')
content = '{ "num": 12345, "name": "On a hill", "area": "Barren hills", "environment": "Hills", "coords": "45,5,4,3", "map": "www.imperian.com/itex/maps/clientmap.php?map=45&level=3 5 4", "exits": { "n": 12344, "se": 12336 }, "details": [ "shop", "bank" ] }'
function RoomInfo (content)
_, _2, t = ROOM_INFO:match(content)
if not system.map[t.exitID] then
system.map[t.exitID] = {}
end
if system.map[t.ID] then
if next (system.map[t.ID]) == nil then
system.map[t.ID] = {
name = t.name,
area = t.area,
--etc
exits = {
[t.exit] = system.map[t.exitID],
},
details = {
t.details,
},
},
LAST_ROOMINFO = content
else
if content == system.map[t.ID].LAST_ROOMINFO then
return
else
system.map[t.ID] = {
name = t.name,
area = t.area,
--etc
exits = {
[t.exit] = system.map[t.exitID],
},
details = {
t.details,
},
},
LAST_ROOMINFO = content
end
end
else
system.map[t.ID] = {
name = t.name,
area = t.area,
--etc
exits = {
[t.exit] = system.map[t.exitID],
},
details = {
t.details,
},
},
LAST_ROOMINFO = content
end
end
I -think- that code works. I'll check it while I'm offline. Also done on the fly, by the way.
EDIT: Quoted the string, I also forgot a space at the beginning of the object. |