Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:21:01+00:00 2026-05-27T10:21:01+00:00

So I’m making a script and I got a function: loot() that returns: {3

  • 0

So I’m making a script and I got a function:

loot()

that returns:

{"3 gold coins"}
{"3 gold coins"}
{"nothing"}
{"6 gold coins", "a hand axe"}
{"12 gold coins", "a hand axe"}

I want that function to be included in a table, and the table should read “a”, “an”, “without a number before the word” = 1

so the table reads and does a count example:

table = {"gold coins"=24,"nothing"=1,"hand axe"=2}

This is the kind of table I’m searching for, but I didn’t have any success doing it at the moment. Like I said before my function loot() returns those messages, these aren’t the only messages that loot reads, but I want to save their number or “a”, “an” as number values for 1, so if it’s “6 gold coins” divides this 6 and increase it in the table when it belongs to the message “gold coins”. I hope you understand my point over here.

The purpose of this is to display the table values so I can do:

table["gold coin"] = 24

or

 table = {["item"]="count",}

so I can request the key. I really want a table that increases a key, rather than a regular table, but I just can’t figure out how to do this…

thanks in advance

and if you can explain me every part of it I’ll be really thankful 🙂

some other msgs :

{"11 gold coins", "a leather helmet", "meat", "a spear", "a gold coin"}
{"a gold coin"}

btw this program, which I’m using to do this its very restricted. All I can use for it, it’s under the lua manual 5.1 link : http://www.lua.org/manual/5.1/manual.html

metatables aren’t an option :/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:21:02+00:00Added an answer on May 27, 2026 at 10:21 am

    The first thing you need is a function that extracts the numbers and items names from strings. The following one will read things like “a spear” or “11 spears” and return 1, “spear” and 11, “spear”.

    function parseAmountAndItem(str)
      assert(type(str)=="string", "Expected a string. Got a " .. type(str))
      -- handle "nothing"
      if str == "nothing" then return nil end
      local item, amount
    
      -- return 1 when it begins with a/an + space
      _,_,item = str:find("^an? (.+)$")
      if item then
        amount = 1
      else -- it should begin with a number + space + singular + s
        _,_,amount,item = str:find("^(%d%d?%d?%d?%d?) (.+)s$")
        assert(amount and item, "Could not parse the string: " .. str)
        amount = tonumber(amount)
      end
      return amount, item
    end
    

    Then you need to accumulate those values. This should work:

    function accumulatedLoot()
      local result = {}
      local amount, item
      for _,row in ipairs(loot())
        for _,str in ipairs(row)
          local amount, item = parseAmountAndItem(str)
          if item then
            result[item] = (result[item] or 0) + amount
          end         
        end
      end
    
      return result
    end
    

    A couple warnings:

    • I’ve written all this by hand, without testing it. It will likely have some syntax errors and/or bugs.
    • I’ve assumed that the plural forms of all your items is the singular form + “s”. Real English is much more complicated. You might need to store a table of irregular plurals and compare it with str instead of just removing the s like I’m doing in the code.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.