I have an urge for the following;
1. Move a bunch of commands, such as speedwalks for instance, to a text file. Each command is prefixed with a self evident tag, separated by the command by a comma.
the text file, in this case is sw.txt, contains as the first few lines;
sw.txt
questor,run 8s
verume,run 2s17e2s6en15e21s2e
jov,run 2s17e2s6en15e21s2e
delf,run 4ne
delf,op n
delf,run 2nw32n8e12neu
2. I then want to be able to enter an alias, such as the alias below,
to load the text file,
interrogate each line,
check for a match for the text up to the first comma,
and if a match on that line, then
send the text following the comma to the mud as a command.
<aliases>
<alias
match="go *"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>for line in io.lines ("sw.txt") do
if "%1" == (string.sub (line,1,(string.find (line, ",")-1))) then
Send (string.sub (line,(string.find (line, ",")+1)))
end -- if
end -- for
</send>
</alias>
</aliases>
Now the amusing thing is, it works just fine to a point. If I execute the command "go questor" it matches the right line, then sends the text to the mud (in this case a speedwalk) and finally I see this error message;
[string "Alias: "]:2: attempt to perform arithmetic on a nil value
stack traceback:
[string "Alias: "]:2: in main chunk
I perform some arithmatic on the string.find function to get rid of the comma from the match and the command. I kinda figure some aspect of the string function is objecting to my brutalisation, fair enough, but it still works to the mud.
Two questions.
1. How to do this without the error as it rather spoils the woohoo factor.
2. You may notice I have a few lines for the same match, that's a workaround to a sequence I want where I can't send the command with a command seperator (as in Send to Execute) so I have to split the command in multiple lines.
One purpose for this is that with more aliases and commands than my age enfeebled memory can handle, I can have bunch of aliases for the same purpose, different spellings for the same alias, amend/add/otherwisedit the commands in a simple file easily. Another pupose is this is a component for my mud.whereis + mud.whereamis and mud.takemethere scripts. Oh, I share the text files and other mud related stuff on my sharepoint server so my lifelong mud partner and I only need one file for each of the things we discover etc.
As always, your help is greatly appreciated. If I've left anything out, poke me for the missing bits.
Fletchling, aka these days, Cuddlepie in aardwolf |