Original Post
I have a lua script that is maintaining information about merging objects: merge a glass with a can of coke, you'll get a glass of coke.
MergeData = {};
function AddMergePair(ob1, ob2, ob3, del1, del2)
-- See if we have any entries for ob1 already...
if(MergeData[ob1] == nil) then
-- No entries for ob1, so let's make one and put the data in it
MergeData[ob1] = {};
end
-- entry for ob1 is guarateed to exist, so put in data for ob2...
MergeData[ob1][ob2] = {ob3, del1, del2};
end
ob1 = string - first object to merge ob2 = string - second object to merge ob3 = string - object to add to player when ob1 and ob2 are merged del1 = bool - do we delete ob1 when we merge del2 = bool - do we delete ob2 when we merge The problem, is that it nevers seems to find that an entry already exists... AddMergePair("chemical", "water", "healingpotion", true, true); this should say "when you merge water onto a chemical, make a healing potion". So after I make the first "chemical", it registers itself into the merge table, and all is well. But if I create a second one (each ob registeres itself on create), then I end up with 2 entries in the MergeData table with a key of "chemical", both with identical data. Is there a better way of checking if a key-value pair already exists? Actually, I don't need to value, just if a key already exists, then add to it's value (which will be another table) and not make a new entry with a duplicate key. I am new to LUA, so I apologize if this is a newbie or dumb question or if my terminology is off.