TempTriggers (sometimes) missing matches table

Post Reply
Sumie
Posts: 1
Joined: Fri May 30, 2025 4:48 am

TempTriggers (sometimes) missing matches table

Post by Sumie »

I'm at a bit of a loss as to why this is happening. It only happens to a few friends system when I share this script with them.

The script in question is a script that creates a bunch of tempTriggers from a list of items in a DB to check the shop stock when you input WARES.

Code: Select all

-- These functions are used to check a shop's wares based on a database entry's requirements. 
-- It will check the shop's min amount and make sure each item meets that amount.
function ShopWaresStart(db_file)
  echo(db_file)
  Shop_Name = db_file
  -- Open DB file given
 
 local mydb = db:create(db_file,
  {
      wares = {
                item_short = "", -- short name of the item for reference. Such as redink
                item_full = "", -- appearance of the item to match for the trigger
                item_type = "", -- Type of item. Such as inks, weapons, etc
                item_min = "", -- Min amount to have in stock before warning
                item_max = "", -- Max amount to recommend to bring the item back up to.
                price = 0, -- price of the item
                shelf = 0,
                _index = { "item_short", "item_full" }
            }
 }) 
  -- fetch the shop results
  shop_wares = nil
  shop_wares = {}
  shop_wares = db:fetch(mydb.wares)
  -- close the DB
  db:close(mydb)
  
  -- table to hold our temp triggers #
  
  -- If our table is not already empty..then this command was run twice before completion. Remove all older triggers.
  if shop_wares_triggers ~= nil then
    for i, v in ipairs(shop_wares_triggers) do
      -- Kill trigger optimizes so it does not remove it right away. So disable to trigger first so it does not fire.
      disableTrigger(v)
      killTrigger(v)
    end
    shop_wares_triggers = nil
  end
  
  shop_wares_triggers = {}
  -- table to hold our current stock
  shop_req_stock = nil
  shop_req_stock = {}
  -- iterate through our database table
  for i, v in ipairs(shop_wares) do
    -- Set our current stock to our min
    shop_req_stock[v.item_short] = tonumber(v.item_min)
    -- Temp trigger for each item to take away from our req stock
    local trig = tempRegexTrigger([[(\w+) (a recharge of |)]] .. v.item_full .. [[ (\[.*\]|)(\s+)(\d+)(\s+)(\d+)gp]], [[shop_req_stock["]] ..v.item_short .. [["] = shop_req_stock["]] .. v.item_short .. [["] - tonumber(matches[6])]])
    -- Add temp triggers id into our table
    table.insert(shop_wares_triggers, trig)
  end
So normally it works. It works all the time on my system and 90% of the time on the other's system, but sometimes it will not fire correctly. It will work when they restart mudlet though and then not work 10% of the time they start mudlet :( .

They will get this error
shopwaresError.png

So this error happens at this tempRegexTrigger

Code: Select all

    local trig = tempRegexTrigger([[(\w+) (a recharge of |)]] .. v.item_full .. [[ (\[.*\]|)(\s+)(\d+)(\s+)(\d+)gp]], [[shop_req_stock["]] ..v.item_short .. [["] = shop_req_stock["]] .. v.item_short .. [["] - tonumber(matches[6])]])
It is because matches[6] is empty. When I had them add `display(matches)` to the tempTrigger it results in..
shopwaresbroken.png

As you can see by {} at the end of the lines. The tempTrigger is firing and matching, but the matches table is empty on some of them. Also when they run the script again, it is random which lines have an empty matches table. This has completely baffled me.

Post Reply