I'm wanting to have an alias to cast a list of spells until the spell casts. Here is how I think it should work, but I'm not sure how to the client to recognize the response from the mud.
Cast the first spell
Check the output from the MUD for "You lost your concentration"
If the return is "You lost your concentration" cast again and check out put.
Cast the next spell in the list if the return is not "You lost your concentration"
How would I get this to work?
Alias to cast spells until success
Re: Alias to cast spells until success
OK I'm probably not the guy to tell you how to do this, because there is probably a better way. However. I have done this same type of things. So I can give you how I do it.
The problem here is that aliases can not check the output, this is what triggers are for. However conveniently aliases can turn on and off triggers as well as create temporary triggers.
So what I would do is create a function for each spell... Something like
function spell1()
send('spell1')
end
function spell2()
send('spell2')
end
etc...
The last trigger should be something like
function spellLast()
disableTrigger('spellTrigger')
end
Then in the same script I would have an array/table of all the spells.
spells={spell1,spell2,...,spellLast)
OK now create a trigger called spellTrigger that fires off ^(.*)$ or whatever regex is going to match your expression. Make sure it is disabled.
Have the trigger do the following
if matches[2]=='You lost your concentration' then
spellCount=spellCount
else
spellCount=spellCount+1
end
spells[spellcount]()
Finally create your starting alias to fire off whatever syntax you choose.. In the script section put...
spellcount=1
enableTrigger('spellTrigger')
spell1() --Alternatively you could use spells[1]()
And that should do it. Once again I'm not pretending this is the best way to do this. And I'm sure there are a lot of people that can tell you a lot better ways to do this. Also there could be timing issues that need worked out if you have to wait a certain amount of time before casting again or your output does come immediately back from the mud etc... But this should get you started as one way to do it although not necessarily the best way.
The problem here is that aliases can not check the output, this is what triggers are for. However conveniently aliases can turn on and off triggers as well as create temporary triggers.
So what I would do is create a function for each spell... Something like
function spell1()
send('spell1')
end
function spell2()
send('spell2')
end
etc...
The last trigger should be something like
function spellLast()
disableTrigger('spellTrigger')
end
Then in the same script I would have an array/table of all the spells.
spells={spell1,spell2,...,spellLast)
OK now create a trigger called spellTrigger that fires off ^(.*)$ or whatever regex is going to match your expression. Make sure it is disabled.
Have the trigger do the following
if matches[2]=='You lost your concentration' then
spellCount=spellCount
else
spellCount=spellCount+1
end
spells[spellcount]()
Finally create your starting alias to fire off whatever syntax you choose.. In the script section put...
spellcount=1
enableTrigger('spellTrigger')
spell1() --Alternatively you could use spells[1]()
And that should do it. Once again I'm not pretending this is the best way to do this. And I'm sure there are a lot of people that can tell you a lot better ways to do this. Also there could be timing issues that need worked out if you have to wait a certain amount of time before casting again or your output does come immediately back from the mud etc... But this should get you started as one way to do it although not necessarily the best way.
Last edited by Zenock on Thu Mar 17, 2011 7:11 pm, edited 2 times in total.
Re: Alias to cast spells until success
Further thought in the previous post I said to use multiple functions That's the way I do it cause I don't want to do just one command. If you want to you can have one functions. Simply set your array up this way...
spells={'spell1','spell2', ...}
and a single function...
function castSpell(number)
if number==LASTNUMBER then
disableTrigger('spellTrigger')
else
send(spells[number])
end
end
And then your trigger script would look like the following...
if matches[2]=='You lost your connection' then
spellCount=spellCount
else
spellCount=spellCount+1
end
castSpell(spellCount)
Your alias would remain the same except you would need to change it to castSpell(1)
Z.
spells={'spell1','spell2', ...}
and a single function...
function castSpell(number)
if number==LASTNUMBER then
disableTrigger('spellTrigger')
else
send(spells[number])
end
end
And then your trigger script would look like the following...
if matches[2]=='You lost your connection' then
spellCount=spellCount
else
spellCount=spellCount+1
end
castSpell(spellCount)
Your alias would remain the same except you would need to change it to castSpell(1)
Z.
Re: Alias to cast spells until success
I had some capitalization problems in there that I finally spotted and fixed. Thanks for the help! Now where should I delay the script to allow the mud to output spell result and then allow the trigger to analyze that output? Should I use a temp timer? Thanks again!
Re: Alias to cast spells until success
The way I set it up is assuming that the mud immediately gives you the results. In other words, after you cast the spell the results will be the next line coming from the mud. If this is true no delay is necessary. If this is not true, then you don't delay, you need to change the trigger so it is watching for the lines your are expecting instead of for ^(.*)$
Sorry about spelling and capitalization errors. Wasn't meant to be cut and paste, was just trying to get it typed out quickly, was meant to help you understand how I would do it.
Sorry about spelling and capitalization errors. Wasn't meant to be cut and paste, was just trying to get it typed out quickly, was meant to help you understand how I would do it.
Re: Alias to cast spells until success
The script is catching a blank line and continuing to fire based off the blank line. I planed around with it some this evening but haven't gotten it to work. Also noticed that any other channel action interferes with the output capture. I'm not sure how to work around this.
And don't worry about the cap errors. I put them in and thought I did a good job looking them over for mistakes like that. Obviously night.
And don't worry about the cap errors. I put them in and thought I did a good job looking them over for mistakes like that. Obviously night.
Re: Alias to cast spells until success
Yeah you are going to want to set it to trigger off what you are expecting to come back...
One line will be
You lost your concentration
I'm not sure what the other will be. But it should be whatever shows a successful spell cast.
Z.
One line will be
You lost your concentration
I'm not sure what the other will be. But it should be whatever shows a successful spell cast.
Z.