Making a table out of a table

Posted by Faedara on Mon 10 Jan 2011 12:39 AM — 12 posts, 49,253 views.

#0
Alright, so I want to match a list displayed like this:

Thaipan, Troel, Arabi, Arakh, Otha, Diavolo, Solymr, Dessa, Santar, Hrekka, Lothenshal, Pilts, Jarik, Mortikai, Vand, Daje,

To compare to a list like this:

Runia, Xae, Lothenshal, Troel, Iocun, Izak, Mina, Naeth, Nephenee, Orklanishkal, Suriyah, Brahmsul, Ashadra, Jackel, Madelyne, Gigvanehldi, Runa, Mortikai, Sheltan, Lacertix,



However...
I'm having trouble figuring out how to pull the names from the first list and make them into a table that highlights matches in the second list...
#1
Whoops, this was supposed to be in General, but I guess making it part of my Lua script would be more effective.
USA #2
Faedara said:

Alright, so I want to match a list displayed like this:

Thaipan, Troel, Arabi, Arakh, Otha, Diavolo, Solymr, Dessa, Santar, Hrekka, Lothenshal, Pilts, Jarik, Mortikai, Vand, Daje,

To compare to a list like this:

Runia, Xae, Lothenshal, Troel, Iocun, Izak, Mina, Naeth, Nephenee, Orklanishkal, Suriyah, Brahmsul, Ashadra, Jackel, Madelyne, Gigvanehldi, Runa, Mortikai, Sheltan, Lacertix,



However...
I'm having trouble figuring out how to pull the names from the first list and make them into a table that highlights matches in the second list...


Okay, so lets say we have a trigger for this. In the Send box, lets split the list by ", " so we have a Lua table containing the names.

local name_array = utils.split("%1", ", ")


However, this makes a table like {[1] = "Runia", [2] = "Xae"}, which makes it very annoying and somewhat difficult to compare to another list. So lets use the names as keys instead of values (i.e. {["Runia"] = true, ["Xae"] = true}. How do we do that? Like this:

local name_array = utils.split("%1", ", ")
local name_set = {}
for k,v in ipairs(name_array) do
  name_set[v] = true
end


Now you can do something like this to see if a name is in the set:
if name_set["Xae"] then
  Note("Xae is online")
end


I hope that helps. If there's anything I missed just let me know.
#3
That would be a very annoying list of notes, I want it to highlight the name in the second list like change the color of the name. In either case, I'm going to try and set this up, to see if I can get it working.
#4
And from what I can tell that would note every time the name appears, though I'm not certain because I haven't fully applied it yet

Alright, guess I didn't make it clear:
Every name that comes up in the first list should be highlighted in the second list.

Example:

List one:

A, E, I, O, U

List two:

A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
Amended on Mon 10 Jan 2011 03:30 AM by Faedara
Australia Forum Administrator #5
My brief response would be, you can make a regular expression that matches a list of alternatives, and inside that put a variable (that is, the list of names).

In particular, I would use something like this:


<triggers>
  <trigger
   custom_colour="3"
   enabled="y"
   expand_variables="y"
   match="(@!friends)"
   regexp="y"
   repeat="y"
   sequence="100"
  >
  </trigger>
</triggers>


Where the variable "friends" looks like:


<variables>
  <variable name="friends">Thaipan|Troel|Arabi|Arakh|Otha</variable>
</variables>


Now you need to put a "|" between each one and not a comma and a space, but that is pretty trivial to do.
#6
Great! I got it up and working! But now I don't know how to add an ally manually...

Say I have a separate variable (since the automated list will be completely erased every time it's set), and I want to add names one at a time based on the following code:


<triggers>
  <trigger
   custom_colour="11"
   enabled="y"
   expand_variables="y"
   group="personalallies"
   ignore_case="y"
   keep_evaluating="y"
   make_underline="y"
   match="\b(@!pallies)\b"
   regexp="y"
   repeat="y"
   sequence="100"
  >
  </trigger>
</triggers>



((That's what I use to highlight))


<aliases>
  <alias
   match="^Ally add (.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="100"
  >
  <send>???</send>
  </alias>
</aliases>


Where ??? is where I need to figure out how to 'add' a variable to a group of variables displayed as such:


<variables>
  <variable name="pallies">Thaipan|Rinoa|Arabi|Arakh|Otha|Diavolo|Solymr|Dessa|Santar</variable>
</variables>
Australia Forum Administrator #7

<aliases>
  <alias
   match="^Ally add (.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="100"
  >
  <send>
SetVariable ("pallies", 
             GetVariable ("pallies") .. "|%1")
</send>
  </alias>
</aliases>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


That just concatenates the new name with the old ones with a "|" between them. This doesn't check if the new name is already in the list.
#8
That's the same conclusion I came to, I figure it works for the purpose so long as I have a clear function with it.

((It empties the variable by setting it to _ so that the singular | doesn't cancel out the variable's usefulness, etc etc))

Thanks Nick!
#9
Sorry to bring this back up, but I can't for the life of me seem to remember how I got the result from capturing into variable form... I'm rapidly unlearning Lua it would seem.

Specifically making the table into a string for SetVariable


<triggers>
  <trigger
   group="Enemies"
   keep_evaluating="y"
   match="*"
   name="Henemycap"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("Henemies", utils.split("%1", ","))</send>
  </trigger>
</triggers>
Amended on Fri 08 Jul 2011 11:38 PM by Faedara
Australia Forum Administrator #10
I'm not sure I understand your question, but maybe this will help:

http://www.gammon.com.au/forum/?id=4960
#11
I wound up finding table.concat. Quite a nice little tool, if I do say so myself :3