Hey friend, I've changed to the following code...
function process_exits (exits_str)
-- generate a "room ID" by hashing the room name, description and exits
-- break up exits into individual directions
exits = {}
for exit in string.gmatch (exits_str, "%w+") do
local ex = valid_direction [exit]
if ex then
exits [ex] = "-666" -- don't know where it goes yet
end -- if
end -- for
if not rooms [current_room] then
rooms [uid] = { name = name, roomdesc = uid, exits = exits, area=area, fillcolour=terrain_color[terrain], fillbrush=0, bordercolour=0xffffff }
end -- if
-- save so we know current room later on
current_room = uid
-- ColourNote ("rosybrown", "", roomdesc)
-- ColourNote ("olive", "", uid)
local room = rooms [current_room]
-- not cached - see if in database
if not room then
-- print ("Loading room", current_room, "from database")
room = load_room_from_database (current_room)
end -- not in cache
if not room then
-- print ("Added room", uid) -- debugging
-- print ("Name", name)
-- ColourNote ("rosybrown", "", roomdesc)
db:exec ("BEGIN TRANSACTION;")
save_room_to_database (current_room, name, roomdesc)
save_exits_to_database (current_room, exits)
db:exec ("COMMIT;")
-- get it back now
room = load_room_from_database (current_room)
end -- if room not there
-- call mapper to draw this rom
mapper.draw (current_room) -- redraw room with name
-- try to work out where previous room's exit led
if expected_exit == "-666" and from_room then
fix_up_exit ()
end -- exit was wrong
end -- process_exits
What I've changed from
if not rooms [uid] then
rooms [uid] = { name = name, roomdesc = uid, exits = exits, area=area, fillcolour=terrain_color[terrain], fillbrush=0, bordercolour=0xffffff }
to if not rooms [current_room] then
rooms [uid] = { name = name, roomdesc = uid, exits = exits, area=area, fillcolour=terrain_color[terrain], fillbrush=0, bordercolour=0xffffff }
Now I'm getting rooms added to the database, but I'm popping an error..
Run-time error
Plugin: Materia_Magica_Mapper (called from world: Demonclient)
Immediate execution
[string "Plugin: Materia_Magica_Mapper"]:589: bad argument #1 to 'gmatch' (string expected, got table)
stack traceback:
[C]: in function 'gmatch'
[string "Plugin: Materia_Magica_Mapper"]:589: in function 'save_exits_to_database'
[string "Plugin: Materia_Magica_Mapper"]:113: in function 'process_exits'
[string "Trigger: Exits_Line"]:1: in main chunk
every time I enter a room.
When I type look again, it's fine, and when I walk back to the previous room, it fixes exits still.
The problem seems to be only when adding the room to the database. The room itself won't draw until I type look again, and I don't get the error code after looking again.
Hrm.. Is it because current_room is something that is saved and loaded into the database like this?
save_room_to_database (current_room, name, roomdesc)
|