[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Making a table out of a table
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Making a table out of a table

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Faedara   (104 posts)  [Biography] bio
Date Mon 10 Jan 2011 12:39 AM (UTC)
Message
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...

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #1 on Mon 10 Jan 2011 12:40 AM (UTC)
Message
Whoops, this was supposed to be in General, but I guess making it part of my Lua script would be more effective.

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #2 on Mon 10 Jan 2011 02:22 AM (UTC)
Message
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.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #3 on Mon 10 Jan 2011 02:50 AM (UTC)
Message
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.

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #4 on Mon 10 Jan 2011 03:14 AM (UTC)

Amended on Mon 10 Jan 2011 03:30 AM (UTC) by Faedara

Message
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

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Nick Gammon   Australia  (21,675 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Mon 10 Jan 2011 06:28 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #6 on Thu 20 Jan 2011 02:48 AM (UTC)
Message
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>

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Nick Gammon   Australia  (21,675 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Thu 20 Jan 2011 06:28 AM (UTC)
Message

<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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #8 on Thu 20 Jan 2011 10:39 AM (UTC)
Message
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!

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #9 on Fri 08 Jul 2011 10:46 PM (UTC)

Amended on Fri 08 Jul 2011 11:38 PM (UTC) by Faedara

Message
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>

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Nick Gammon   Australia  (21,675 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Sat 09 Jul 2011 07:14 AM (UTC)
Message
I'm not sure I understand your question, but maybe this will help:

http://www.gammon.com.au/forum/?id=4960

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #11 on Sat 09 Jul 2011 08:15 AM (UTC)
Message
I wound up finding table.concat. Quite a nice little tool, if I do say so myself :3

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] 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.


8,417 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]