Search Script

Posted by DanPrice on Sat 01 Jun 2002 03:11 PM — 3 posts, 14,929 views.

Australia #0
okay, another question for you guys:
I have logged all of the information on items in the mud I play into one big text file, with each thing seperated by a enter, e.g:

Object 'the Cloak of Shadows', Item type: OTHER
Item will give you following abilities: NOBITS

Object 'thracian half-armor', Item type: ARMOR
Item will give you following abilities: NOBITS

Now i am trying to make a script to search through this for an item name (e.g. 'the cloak of shadows') and then display the results. So far all I can do is open the file and read the lines. Any suggestions on how to go about matching on the item name and displaying its info?
USA #1
Hmm. Not sure. I assume that the names are added as you found them and not sorted. If they are sorted then there may be a fairly efficient way to do it, but unsorted you are going to waste an insane amount of time hunting for each match. In either case I haven't done much with file access in scripts, so am not sure if it can even be done. Also.. In the old QBasic there where file setting from reading 'records', but you either had to use a fixed length and read the data as a specific type with the same size, read it sequentially every time, or avoid things like ',', because it treated ',', ':' and enter as seperate records. It isn't likely to be easy this way. A better solution would be to hunt through these forums for a set of posts on accessing databases from in scripts. Since the drivers for ODBC support both searching, automatic sorting and executes outside the client, there should be a minimum speed penalty when using it, compared to trying to use a text file.
Australia Forum Administrator #2
Depending on the quantity you could add them as MUSHclient variables. That would give a direct lookup (by name).

Alternatively, and perhaps quicker, do what Shadowfyr recommended and use a database. There was a post about that. You could use MySQL which is free.