Hoplo said: However, the memt table is populated by "meaningful members" that work just fine. No it is not. Not when the spell isn't already in the table.
Quote: Then, I believe, the issue is not simple ensuring there is a .mem to subract, but the whole parent subtable of the spell name the .mem is applied to exists.
The error message you posted does not support your belief.
Here's the thing. Your metatable trick worked. It's a silly thing to do because it clearly solves only half of your original problem (you tried to access a member of nil), and does so in a way you don't understand, but it did work. memt[spell_cast] will no longer return nil.
Much more sane would have been to check if memt[spell_cast] is null and create a new table on that condition with the appropriate mem value. Or better yet, not a table at all. Tables containing a single member are silly. You might as well just make memt[spell_cast] store the value mem directly.
But now you have just punted your nil problem down the field. memt[spell_cast] no longer returns nil, it returns an empty table. Your problem now is that empty tables are empty. They do not contain mem. So trying to access .mem returns nil. This is only a problem when you try to subtract 1.
Quote: I did try Nick's suggestion, with the same error being returned. I doubt that. What Nick posted would solve the error you showed given the code you showed. Please post your new code and new error message. |