saving data - Lua: Why does my table revert to nil after one remove? -


the following part of script use indicate items (in case, mobs in mud) not in tabled database.

if mqtable[1] == nil   note("no mobs missing database!")  else   if "%1" ~= ""   mindex = "%1"   mdesc = mqtable[tonumber(mindex)]   end if "%2" ~= "" mlvl = "%2" end if "%3" ~= "" mkeyw = "%3" end if not mindex , mqtable[1]   tprint(mqtable) elseif mindex , not mlvl   note(mdesc) elseif mindex , mlvl , not mkeyw   note("syntax is: mqmob [index] [level] [keywords]") else   mobtable[mdesc]={level = mlvl, keywords = mkeyw}   table.save(mobtable,savepath.."/mobs/"..areazone..".tbl")   note(mqtable[tonumber(mindex)] .. " saved. level: ".. mlvl .. " -- keywords: " .. mkeyw)   table.remove(mqtable, tonumber(mindex))   mobtable = table.load(savepath .. "/mobs/" .. areazone .. ".tbl")   mlvl, mkeyw, mdesc = nil, nil, nil end 

assume undefined functions working intended , not appear root cause. "%1", "%2", , "%3" passed parameters through trigger. essentially, if function, 3 parameters called foo(blah, bleh, blargh).

problem

if type mqmob (which fires above script), displays within room mobs have not been added table. use mqmob <index> <level> <keyword> add mob table. once has been done, however, script refuses work, , regardless of number of items on table, mqmob returns nil. why table being wiped after storing 1 bit of information?

example

i in room , see following:

a rat dwells here. mouse chases after cheese. spider makes home in corner. flea leaps playfully. 

say have a spider makes home in corner. in database. remaining 3 descriptions placed mqtable, , when call mqmob, displays:

1="a rat dwells here." 2="a mouse chases after cheese." 3="a flea leaps playfully." 

now, type mqmob 1 20 rat create mobtable["a rat dwells here."] {level = 20, keywords = rat}. once that, if type mqmob again, returns nil.

explanation of variables

mobtable merely table contains mob's description key, , corresponding level , keywords values. example:

mobtable = {"a rat nibbles on cheese." = {keyword = "rat", level = 20}} 

mqtable populated when there no corresponding match in mobtable. essentially, trigger fires, compares keys in mobtable, , if not found, populates mqtable. prevent me unnecessary work of adding mobs in mobtable.

the problem keep running add 1 mob, when run print command second time, returns nil. however, can still add , view individual indexes in mqtable. doesn't seem able print anymore.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -