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 ➜ Using trigger to make table and sub tables

Using trigger to make table and sub tables

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


Posted by Hoplo   (16 posts)  Bio
Date Mon 23 Jul 2012 06:53 PM (UTC)
Message
Hi, I have read through many different posts on the forums trying to figure out how to do what I want to do. This includes the nice tutorial/help on lua tables, as well as other posts asking about tables, and I still can not quite grasp all the components I need.

What I would like to do is capture a bunch if information after typing : group

example text after command:
Your group of 10 members consists of:
Member Hits Move Position Fly Inv Water iMT Here Light Mem
---------------------------------------------------------------------------------
Bob perfect rested standing Y N N N Y 0 0
Rob good rested standing Y N Y Y Y 0 0
Lob bad rested sitting Y N Y Y Y 2 0
Top

Posted by Hoplo   (16 posts)  Bio
Date Reply #1 on Mon 23 Jul 2012 06:57 PM (UTC)
Message
I have used this trigger to capture information, but I am not exactly sure what to do with it.

<triggers>
<trigger
enabled="y"
group="autoheal"
match="^ ([A-Za-z]+)\b\s+([A-Za-z\.]+)\b\s+([A-Za-z]+)\b\s+([A-Za-z]+)\s+([YN])\s+([YN])\s+([YN])\s+([YN])\s+([YN])\s+(\d+)\s+(\d+)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>table.insert(groupArr, ("%0"))</send>
</trigger>
</triggers>

This trigger works well for capturing the information and storing into a table (groupArr) as a single string. But, ultimately what I would like to do is form sub-tables for each character name with the information so that i can access each given information provided individually.

Example: make a trigger to check to see if Bob is flying, or sitting, or in bad condition so that i can fly whoever needs flying or heal someone who is at bad health.

Top

Posted by Fiendish   USA  (2,558 posts)  Bio   Global Moderator
Date Reply #2 on Tue 24 Jul 2012 02:48 AM (UTC)
Message
try

table.insert(groupArr, {"%1","%2","%3","%4","%5","%6","%7","%8","%9","%10","%11"})

or even

groupArr["%1"] = {"%2","%3","%4","%5","%6","%7","%8","%9","%10","%11"}

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Hoplo   (16 posts)  Bio
Date Reply #3 on Tue 24 Jul 2012 04:48 AM (UTC)

Amended on Tue 24 Jul 2012 04:55 AM (UTC) by Hoplo

Message
groupArr["%1"] = { hits = "%2", mv = "%3", pos = "%4", fly = "%5", inv = "%6", wb = "%7", imt = "%8", here = "%9", light = "%10", mem = "%11"}

Thanks, this is what I was thinking of, and so much simpler then I thought it would be.

to test the information in the new groupArr table I used:
require "tprint"
tprint (groupArr)

this gave a slight problem and I am not sure why.

*not sure why this is not spacing correctly...
"Silbo":
"mem"="Silbo1"
"light"="Silbo0"
"inv"="N"
"here"="N"
"wb"="N"
"imt"="Y"
"fly"="N"
"pos"="sitting"
"mv"="rested"
"hits"="perfect"
"Bob":
"mem"="Bob1"
"light"="Bob0"
"inv"="N"
"here"="Y"
"wb"="N"
"imt"="Y"
"fly"="Y"
"pos"="resting"
"mv"="rested"
"hits"="perfect"

the "mem" and "light" entries in each are not correct, as the mud shows this:

Rob perfect rested resting Y N N Y Y 1 1
Bob perfect rested standing N N N Y Y 0 0

Also, just to make sure... I can access these new variables globally by something like: groupArr.rob.hit ??
Top

Posted by Hoplo   (16 posts)  Bio
Date Reply #4 on Tue 24 Jul 2012 05:19 AM (UTC)

Amended on Tue 24 Jul 2012 05:23 AM (UTC) by Hoplo

Message
Ok I think I am starting to get it. I tried this:

print (table.foreach (groupArr,
function (k, v)
if v.here == "Y" then
return k
end -- if
end -- function
))

and with the information pasted from the last message I got a return of:

Bob

Which is correct, as he was the only one "here".

BUT, if i have both groupies in the same room and both are "here" it only returns the top one.
Top

Posted by Fiendish   USA  (2,558 posts)  Bio   Global Moderator
Date Reply #5 on Tue 24 Jul 2012 12:29 PM (UTC)

Amended on Tue 24 Jul 2012 12:36 PM (UTC) by Fiendish

Message
Hoplo said:
the "mem" and "light" entries in each are not correct, as the mud shows this:
Ahhh... Oops.
That's because %10 and %11 are getting parsed as "%1" and 1. and "%1" and 0. My mistake.
Use %<10> and %<11> instead.

Scroll down to 'Using the wildcard in the "send" box ...' on http://www.gammon.com.au/scripts/doc.php?general=triggers


Quote:

Also, just to make sure... I can access these new variables globally by something like: groupArr.rob.hit ??
Globally? No. Inside that script, yes. If you want to access them globally you'll need to read about serializing lua tables to mushclient variables.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Fiendish   USA  (2,558 posts)  Bio   Global Moderator
Date Reply #6 on Tue 24 Jul 2012 12:35 PM (UTC)
Message
Hoplo said:

Ok I think I am starting to get it. I tried this:

print (table.foreach (groupArr,
function (k, v)
if v.here == "Y" then
return k
end -- if
end -- function
))

and with the information pasted from the last message I got a return of:

Bob

Which is correct, as he was the only one "here".

BUT, if i have both groupies in the same room and both are "here" it only returns the top one.


table.foreach is deprecated anyway. Use

for k,v in pairs(groupArr) do
   if v.here == "Y" then
       print(k)
   end
end

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Hoplo   (16 posts)  Bio
Date Reply #7 on Tue 24 Jul 2012 05:09 PM (UTC)
Message
for k,v in pairs(groupArr) do
if v.here == "Y" and v.mv == "fatigue" then
if k == "%1" then
print(k)
end
end
end

this is a test alias to see if this all did what I wanted to do. The goal is to eventually make a trigger that checks the group and then casts spells like fly if someone needs it. In this case I am checking both their movement and if they are in the room so i can refresh their movement. It seems to work. If anyone has a better suggestion i would love to hear it because I am still fairly new at this.
Thanks for all the help so far, these forums have helped a ton
Top

Posted by Hoplo   (16 posts)  Bio
Date Reply #8 on Sat 11 Aug 2012 10:41 PM (UTC)

Amended on Sun 12 Aug 2012 03:18 AM (UTC) by Nick Gammon

Message
Hello. I have been using one of the examples Fiendish gave:
groupArr["%1"] = {"%2","%3","%4","%5","%6","%7","%8","%9","%10","%11"}

It works great for all the stuff I wanted this table to do. However, I was wondering if there was a way send this table information to a mini-window. I am not looking for anything too fancy. I have watched and read the examples like http://gammon.com.au/forum/bbshowpost.php?id=9965, but all of these examples use a wait to capture the information as a single line. I am not really sure how to insert something like the above table into the windowtext.

Something simple like,

WindowCreate (win, 0, 0, 105, 15, 8, 0, ColourNameToRGB("yellow"));
WindowFont (win, "f", "Lucida Console", 9, true, false, false, false, 1, 0);
WindowText (win, font, groupArr, 5, 2, 0, 0, ColourNameToRGB ("black"), false);
WindowShow (win, true);
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #9 on Sun 12 Aug 2012 03:19 AM (UTC)
Message
See here: http://www.gammon.com.au/mushclient/mw_text.htm

Near the bottom are examples of displaying lines of text with small helper functions.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Hoplo   (16 posts)  Bio
Date Reply #10 on Sun 12 Aug 2012 03:53 AM (UTC)
Message
Thank you :) I have seen those, still working around them.

I remembered something someone mentioned in some other post where %0 is the whole string captured, and this is what i was looking for.

Thanks for the quick reply, and all the help from the forums.
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.


34,510 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.