Selecting a table via variable

Posted by Deiwos on Sun 15 Mar 2015 01:52 PM — 2 posts, 11,282 views.

#0
Hello. I've been trying to figure out if this is possible without any luck (exacerbated by my.. extremely limited programming experience), but what I want to do is accept a wildcard from an alias, and use a table based on that wildcard. I can't find how for the life of me.

For example: say I want to make a health elixir. I -could- write a script that has an 'if elixir == "health" then do' for each elixir I can make, but what I would rather do is have a selection of tables listing the ingredients for each, and then send them to a single function that takes the table named after the elixir I want, reads the ingredient values in the table, and produces an elixir from that.

It would be something like:

function Transmutate (name, line, wildcards)

Health = {"realgar", "plumbum", "ferrum", "bisemutum"}

elixir = GetVariable("elixir")
vial = GetVariable("vial")

  for i = 1, 4 do
    for n = 1, <table length from 'elixir' variable> do
      Send("outr 1", <table name from 'elixir' variable>[n])
    end
  end
  Send("transmutate 4 ", elixir, " in alembic")
  Send("decant alembic into ", vial, " 4 times")
end


Thus I would use this by something like 'tm Health vial1'.

Is this at all possible? Am I thinking about this the wrong way?
Amended on Sun 15 Mar 2015 02:19 PM by Deiwos
Australia Forum Administrator #1
A simple solution would be to make a table of tables, which is easy.

For example:


potions = {
  Health = {"realgar", "plumbum", "ferrum", "bisemutum"},
  Poisons = { "a", "b", "c" },
  Strength = { "d", "e", "f" },
  }


Now you index into "potions" table to get the sub-table which is the list of elixers of that sort.