Register forum user name Search FAQ

Gammon Forum

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 ➜ General ➜ Help with Tables

Help with Tables

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


Posted by Deladan   (40 posts)  Bio
Date Tue 24 May 2011 08:41 PM (UTC)
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>
Top

Posted by Deladan   (40 posts)  Bio
Date Reply #1 on Tue 24 May 2011 10:10 PM (UTC)
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
Top

Posted by Deladan   (40 posts)  Bio
Date Reply #2 on Tue 24 May 2011 11:01 PM (UTC)
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
Top

Posted by Deladan   (40 posts)  Bio
Date Reply #3 on Wed 25 May 2011 12:19 AM (UTC)
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
Top

Posted by Deladan   (40 posts)  Bio
Date Reply #4 on Wed 25 May 2011 05:32 AM (UTC)
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?
Top

Posted by Deladan   (40 posts)  Bio
Date Reply #5 on Wed 25 May 2011 05:40 AM (UTC)
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
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #6 on Wed 25 May 2011 06:16 AM (UTC)
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
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.


16,999 views.

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

Go to topic:           Search the forum


[Go to top] top

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