Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Selecting a table via variable
|
Selecting a table via variable
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Deiwos
(6 posts) Bio
|
| Date
| Sun 15 Mar 2015 01:52 PM (UTC) Amended on Sun 15 Mar 2015 02:19 PM (UTC) by Deiwos
|
| Message
| 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? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Mon 16 Mar 2015 07:39 AM (UTC) |
| Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
10,418 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top