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
➜ Tips and tricks
➜ help with table.insert
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| AquaBrother
Brazil (19 posts) Bio
|
| Date
| Mon 22 Nov 2010 05:05 PM (UTC) |
| Message
| Hi, i'm trying to do something i should not, hehe, once i have not enough experience on doing it...
Well, i'm trying to make a search in an especific table but i cannot find the right command to use...
I have a table called {friends}
I use the table.insert to insert new friends name in that table, i've read about a few functions on the internet that would find that name but, what i really need is making it search all name that fits with a sentence, eg:
if i type for example:
friend mike
and lez imagine that i have two friends named mike and mikein, i'd like that search to inform me that there are two names within the setence i just type...
Is that possible?
big trouble huh? if you feel like too busy or like it's too much trouble for answering that, nevermind...
Thx in advance | | Top |
|
| Posted by
| Fiendish
USA (2,547 posts) Bio
Global Moderator |
| Date
| Reply #1 on Mon 22 Nov 2010 05:28 PM (UTC) |
| Message
| I don't exactly understand. Is "friend mike" the sentence?
Can you give a better example of what you want to type and what you want to get as a result? |
https://github.com/fiendish/aardwolfclientpackage | | Top |
|
| Posted by
| AquaBrother
Brazil (19 posts) Bio
|
| Date
| Reply #2 on Mon 22 Nov 2010 05:42 PM (UTC) |
| Message
| hehe, ok, i'll try to explain again...
I have the following table already made:
Mike
Mikein
Milan
Mordon
ETC...
I wanna type:
Friend mike
I wanna get as result:
There are two mike in your table:
Mike
Mikein
| | Top |
|
| Posted by
| Fiendish
USA (2,547 posts) Bio
Global Moderator |
| Date
| Reply #3 on Mon 22 Nov 2010 05:55 PM (UTC) Amended on Mon 22 Nov 2010 05:56 PM (UTC) by Fiendish
|
| Message
| Off the top of my head, assuming you have along the lines of
friends = {"Mike", "Mikein", "Mikeout", "Wanda", "Jeff"}
I think you could make an alias with the pattern "friend *" that does the following:
local result = {}
local name = string.lower(%1)
for i,v in ipairs(friends) do
if string.find(string.lower(v),name) ~= nil then
table.insert(result,v)
end
end
print("There are "..#result.." "..%1.." in your table:")
for i,v in ipairs(result) do
print(v)
end
You may want to replace the print commands with something like Note or ColourNote. |
https://github.com/fiendish/aardwolfclientpackage | | Top |
|
| Posted by
| AquaBrother
Brazil (19 posts) Bio
|
| Date
| Reply #4 on Mon 22 Nov 2010 06:17 PM (UTC) |
| Message
| hehe, thx Fiendish i appreciate your help, i think that will work for now...
Thx for your time =)
Best regards | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Mon 22 Nov 2010 08:28 PM (UTC) |
| Message
|
Fiendish said:
local result = {}
local name = string.lower(%1)
You need to quote the %1 there (and further down), otherwise it expands to:
local name = string.lower(Mike)
... which is referring to the non-existent variable Mike.
It should read:
local result = {}
local name = string.lower("%1")
Ditto for lower down where it displays the results.
print("There are " .. #result .." %1 in your table:")
It would also help to make a "plain" search in case you happened to search for (say) ^Mike, so it could read:
if string.find (v:lower (), name, 1, true) then
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Fiendish
USA (2,547 posts) Bio
Global Moderator |
| Date
| Reply #6 on Mon 22 Nov 2010 08:34 PM (UTC) |
| Message
| | Heh. I suppose I should have actually tried it out first. :) |
https://github.com/fiendish/aardwolfclientpackage | | 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.
21,832 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top