Well, what was wrong with it was a collection of small syntax errors that weren't breaking things on their own, I was interpreting what was going on incorrectly, and because my code was too unwieldy to put into concise form on a message board, I revised it into a simpler form, one where those errors were no longer appearing. The apparent interaction with modularity and dofile prevented me from double checking my paraphrase on the online Lua console I use.
Where I keep running into problems is trying to get scope to penetrate, and keeping track of my references to self, but my knowledge isn't yet at the point where I can even phrase my problems correctly. (For instance, after a bit of experimentation, I found loadfile and dofile working differently in how they handled scope, but I don't understand why. Or rather I think they did, but once I got my code working, I stopped looking at their differences.) I guess I've just got to face up to the fact that it takes more than three weeks to learn how to code well, and I'm just making too many errors and not noticing them for too long. Periods that should be colons are frequent offenders; recently, it took an awfully long time away from the computer to see that a "for in pairs(t)" lacked the "pairs".
I'm embarassed of asking for help when the answer comes to me eventually, and especially when I don't phrase things in such a way that anybody could ever help, but I also feel like it's just part of how I solve problems-- the problems are getting complicated enough that trying to describe them in English is part of the solution. I guess I'm saying don't judge me too harshly for long, useless, difficult-to-understand posts like this
I appreciate the link: it would certainly be a good idea for me to worry about limiting scope more than I do. (It's occurred to me that by using dofile(), I'm probably making a mod where somebody who wants to can get a highly cheated character onto the vault, but frankly, I'm more worried about just accessing my variables from various scopes.)
setfenv sounds like something I need to read about. I'll look around a bit. It's probably a little out of my depth still, but reading stuff before I understand it seems like the way to get to a point where I can eventually understand it. Looking at metatable tutorials, they've seemed like "other ways to do things that make your code prettier," when I'm not even good enough at the basics to worry about that, but it does seem that it's time to start dipping my toes into it.
Thanks for looking. Sorry that I made you look at lies. (edit: hey, cool, i just managed to control my reference to "self" in a useful way on the first try, guess I'm getting somewhere)