View RSS Feed


Don't play with your Lua at the table...

Rate this Entry
I never really "learned" Lua as a programming language. I just sat down one day and decided to write stuff in it. I read a few tutorials on the internet about the basics, look at some code examples and off I went! While this method kinda works it does cause me some headaches here and there because I can get tripped up at the most simple of problems.

I was playing with a function to load an object or item into a room but nothing was keeping track of how many there were so every time it was called, another object would pop. How frustrating, but ok, fine, I'll check to see how many of them are out in the world first. Error! Ugh.

"Attempt to index local 'obj' (a number value)"

Well at this point an object could either be a single vnum or a table of vnums for a container. I happened to be loading a chest on the ground so my little function was dying because it was expecting a number and getting a table. And HERE is where I got stuck for over an hour!

Turns out, the solution was simple enough though probably not the most elegant of one.

if type(obj) == 'number' then
tempobj = obj
tempobj = obj.container

Now my function to count the number of an item already loaded is much happier because its only getting a single vnum and not a table by mistake. And I can move on to the next problem....


The (updated) legal stuff: This does not mean it will happen, this does not mean it'll be in v5, this does not mean it’s a rule or a policy, this does not mean it’s about a specific person (except in certain cases), this is not intended to call out anyone, this does not mean anyone but ME thinks this way, this is not always the opinion of the other God+ staff, this doesn't mean that I'll finish what I started, this does not mean anything more than I happened to be pondering something. k thx bai!

Submit "Don't play with your Lua at the table..." to Digg Submit "Don't play with your Lua at the table..." to Submit "Don't play with your Lua at the table..." to StumbleUpon Submit "Don't play with your Lua at the table..." to Google

Tags: None Add / Edit Tags


  1. eldric's Avatar
    Geez, there are so many languages. I hadn't heard of lua. I've recently got back into C programming for fun - better than watching TV. I want to pick up ruby though. Is lua a scripting language?
  2. Natilena's Avatar
    Oui! A scripting language. Easily embedded (well maybe it is if you're know what you're doing!) and pretty easy to use. I've seen my kids trying to learn it with Roblox and Garry's Mod, WoW uses it too. Neat stuff.
  3. Maimer's Avatar
    I've been using mudlet lately, which uses lua pretty heavily. It is somewhat a step-up from tintin++... sort of stuck with that ever since using it on the old Primenet shell account. Still... coming from a c++/c# background scripting languages just sort of irk me... and ruby ick..use it, I've had a few ruby projects but they are not my fave. Groovy is about the only scripting language I like.. and thats only because it will fall back to Java.
  4. Natilena's Avatar
    I looked at ruby a bit but just shivered and moved on, I think Tynian looked at Python. Lua had this nice C API and a few good examples out there so Lua it is. I really do get a kick out of seeing my kids trying to learn it and decided one upping them would amuse me.

    I've been looking a lot in to different client capabilities and tintin++ has moved up in the world. There's a lot of scripting capability there now, especially if you have MSDP which I've been poking at. MSDP (and MXP for that matter) ... fodder for a later blog post! Gotta get my content somewhere!


Total Trackbacks 0
Trackback URL: