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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Help with Tables
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Help with Tables

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Deladan   (40 posts)  [Biography] bio
Date Tue 24 May 2011 08:41 PM (UTC)  quote  ]
Message
Here goes, I'm trying to make a table that will track every person that I happen to enemy and then remove them when I unenemy them. The triggers would be

^(\w+) is now one of your enemies\.$

to add to the table

and

^You declare that (\w+) will no longer be one of your enemies\.$

^In a moment of forgiveness, you declare that you have no enemies\.$

to remove from the table

now what I'd like done with the table is to turn it into a varibable so that I can modify the trigger that Nick helped me with (see did for me basically) to look like this


<trigger
custom_colour="17"
enabled="y"
expand_variables="y"
group="Highlights"
ignore_case="y"
match="^With a sudden convulsion, (\w+) collapses helplessly to the ground\.$"
regexp="y"
send_to="12"
sequence="100"
other_text_colour="lime"
>
<send>if "@enemies" == "%1" or if "@target" == "%1" then
ColourNote("white", "green", "%1 is prone!!!")
end
</send>
</trigger>
[Go to top] top

Posted by Deladan   (40 posts)  [Biography] bio
Date Reply #1 on Tue 24 May 2011 10:10 PM (UTC)  quote  ]
Message
So after talking with some people the trigger can be done like this


<trigger
custom_colour="17"
enabled="y"
expand_variables="y"
group="Highlights"
ignore_case="y"
match="^With a sudden convulsion, (\w+) collapses helplessly to the ground\.$"
regexp="y"
send_to="12"
sequence="100"
other_text_colour="lime"
>
<send>if "@enemies" == "%1" or "@target" == "%1" then
ColourNote("white", "green", "%1 is prone!!!")
end
</send>
</trigger>

now I just wish I knew how to do a simple enough table to do what I want
[Go to top] top

Posted by Deladan   (40 posts)  [Biography] bio
Date Reply #2 on Tue 24 May 2011 11:01 PM (UTC)  quote  ]
Message
^(\w+) is now one of your enemies\.$

would you do

enemies = {} -- To create the table

but I don't know how to add to the table from a trigger
[Go to top] top

Posted by Deladan   (40 posts)  [Biography] bio
Date Reply #3 on Wed 25 May 2011 12:19 AM (UTC)  quote  ]
Message
^(\w+) is now one of your enemies\.$

would you do

enemies = {} -- To create the table

enemies ["%1"] = 0 -- puts the person in the table?


and from there I'm lost completely
[Go to top] top

Posted by Deladan   (40 posts)  [Biography] bio
Date Reply #4 on Wed 25 May 2011 05:32 AM (UTC)  quote  ]
Message
^(\w+) is now one of your enemies\.$

would you do

enemies = {} -- To create the table

enemies ["%1"] = 0 -- puts the person in the table?


-- sort enemies into alphabetic order
sorted_enemies = {}
for name in pairs (enemies) do table.insert (sorted_enemies, name) end
table.sort (sorted_enemies)


am I right so far?
[Go to top] top

Posted by Deladan   (40 posts)  [Biography] bio
Date Reply #5 on Wed 25 May 2011 05:40 AM (UTC)  quote  ]
Message
^(\w+) is now one of your enemies\.$

would you do

enemies = {} -- To create the table

enemies ["%1"] = 0 -- puts the person in the table?


-- sort enemies into alphabetic order
sorted_enemies = {}
for name in pairs (enemies) do table.insert (sorted_enemies, name) end
table.sort (sorted_enemies)

-- show enemies
if next (enemies) then
ColourNote ("red", "", "enemies now consists of " ..
table.concat (sorted_enemies, ", "))
end

I hope that's right
[Go to top] top

Posted by Nick Gammon   Australia  (19,375 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Wed 25 May 2011 06:16 AM (UTC)  quote  ]
Message
Quote:

enemies = {} -- To create the table

enemies ["%1"] = 0 -- puts the person in the table?


You don't want to keep recreating the table, or it will only ever have one person in it. So do this instead:


enemies = enemies or {} -- To create the table


Or to have much the same effect:


-- if table does not exist, create it
if not enemies then
  enemies = {} -- To create the table
end -- if



Then:


enemies ["%1"] = true -- puts the person in the table


To remove that person:


enemies ["%1"] = nil -- removes the person in the table


You can print them in sorted order like this:


  require "pairsbykeys"
  for who in pairsByKeys (enemies) do
    print (who)
  end -- for



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


1,389 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]