Lua Table Indexing

by Simimi

Back to Mechanic's Corner.

Simimi2007-07-16 13:50:34
Still working on that old system... I ran into a new problem the first time I tried to work with actual afflictions. I have lookup tables for various afflictions and such in my script. Here is the issue currently.

When I am hit with an affliction I get this error.
CODE
un-time error
World: Lusternia
Immediate execution
:1: table index is nil
stack traceback:
        :1: in main chunk


The trigger it is referring to is...
CODE
^cursed by manabarbs\\.$

This is supposed to send the affliction to a table of current afflictions called "affs" such that;
CODE
affs = true OR addaff (manabarbs, true)

adds the aff to
CODE
affs = {}



Now, I said OR because I tried them both, as I was not sure which was the proper way to set the affliction in the table. The affliction source I am using was given to be to use by Zarquan and Demetrios in my old thread, entitled Prompt Trigger Question. This is it.

CODE
function addaff(aff, val)
  -- If it's not a valid affliction name, leave the
  -- function early to avoid crashing
  if not aff then
    return
  end

  -- This will default "val" to true if it's omitted from
  -- the arguments passed in
  val = val or true

  -- You can pass in a table of afflictions to save calls,
  -- or you can omit this as it's really just extra fun
  if type(aff) == "table" then
    for _,v in pairs(aff) do
      addaff(v, val)
    end
    return
  end

  -- The actual setting of the affliction in the table
  affs = val

  -- This is where I set flags on which healing
  -- queues to check on the next prompt, but
  -- you do your curing however you like...
end



I am clearly doing something simple, incorrectly. I am at a loss at the moment, any ideas?