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
➜ Lua
➜ testing color of variable captured by trigger
testing color of variable captured by trigger
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Burzmali
(10 posts) Bio
|
Date
| Sat 16 Dec 2006 04:32 PM (UTC) |
Message
| I am wondering if it is possible to test for the color of a variable captured by a trigger. For example can you test if the third wildcard captured %3 has been outputted by the mud in the color cyan?
| Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 16 Dec 2006 07:10 PM (UTC) |
Message
| You can in Lua if you call a script (not do "send to script") as the fourth argument to a script in Lua is a table of the style runs, which includes the colour for each style.
In other languages you could use GetStyleInfo:
http://www.gammon.com.au/scripts/doc.php?function=GetStyleInfo
This lets you find the style runs for any line in the output window, presumably for a trigger the matching line is the last one, unless it spans multiple lines (which it might if it wrapped around).
However style runs are not wildcards exactly, but if the nature of the trigger is that, if it fires, the thing you want to test is always a different colour, then you just need to work out which style run it is. Each change of text style (eg. from one colour to another, or from bold to normal) creates a style run. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Burzmali
(10 posts) Bio
|
Date
| Reply #2 on Sat 16 Dec 2006 09:19 PM (UTC) |
Message
| thank you for your quick response. I am waiting to see
if i get a lua manual for christmas before i go and get one
for myself so i will be using lua but am not familiar with it yet. Below is an example of the sort of output involved.
Level: 15 Avoidance Mana: 25 Learned: 100% (168)
If the word Avoidance is green the spell is active. If it is cyan then it is not active and needs to be recast. what might a simple trigger be to detect if it is cyan and recast it? | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #3 on Sat 16 Dec 2006 10:57 PM (UTC) |
Message
| http://www.lua.org/pil/
is a great way to learn Lua. It's the first version of Programming in Lua, available for free online. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sat 16 Dec 2006 11:40 PM (UTC) |
Message
| The easiest way, if you are going to use Lua (in which case we are really in the wrong forum section), is to download the latest version of MUSHclient first (3.83 onwards):
http://www.gammon.com.au/forum/?id=7533
Then I would make a trigger to work out which style run the word "Avoidance" is in. Something like this works for my prompt line:
<triggers>
<trigger
enabled="y"
match="<*/*hp */*m */*mv */*xp>*"
omit_from_output="y"
send_to="14"
sequence="100"
>
<send>
require "tprint"
tprint (TriggerStyleRuns)
</send>
</trigger>
</triggers>
If I run this I get this output from my prompt:
<100/100hp 143/143m 210/210mv 0/343xp>
1:
"textcolour"=12632256
"backcolour"=0
"length"=1
"style"=0
"text"="<"
2:
"textcolour"=65535
"backcolour"=0
"length"=10
"style"=1
"text"="100/100hp "
3:
"textcolour"=16776960
"backcolour"=0
"length"=9
"style"=1
"text"="143/143m "
4:
"textcolour"=65280
"backcolour"=0
"length"=10
"style"=1
"text"="210/210mv "
5:
"textcolour"=16711935
"backcolour"=0
"length"=7
"style"=1
"text"="0/343xp"
6:
"textcolour"=12632256
"backcolour"=0
"length"=1
"style"=0
"text"=">"
From this you can see which style run is associated with which part of the line. Say it turns out that "Avoidance" is style run 3. Then you can amend the trigger to look something like this:
<triggers>
<trigger
enabled="y"
match="Level: * Avoidance Mana: * Learned: *% (*)"
omit_from_output="y"
send_to="14"
sequence="100"
>
<send>
if TriggerStyleRuns [3].text == "Avoidance" and
TriggerStyleRuns [3].textcolour == 16776960 then -- cyan
Send ("cast avoidance")
end -- if need to cast it
</send>
</trigger>
</triggers>
You might need a bit of trial and error to get the colour right. You can always add into the script:
print (TriggerStyleRuns [3].textcolour)
That would show the exact number that is being displayed each time, that way you can work out what number is cyan. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Burzmali
(10 posts) Bio
|
Date
| Reply #5 on Mon 18 Dec 2006 02:10 AM (UTC) |
Message
| Thanks again for your response. I see what you mean about wrong forum - jscript and all. Sorry, new to all this. I am obviously missing something very fundemantal to this whole business. I copied and pasted your response to notepad and edited the match so it could match what i have in my prompt. Scripting is enabled and lua is the language. when i entered the 1st script into the command line i got a bunch of errors from the mud saying not a command, dont know what you mean, not a command etc. I then tried it as an alias and sent it to script and got a compile error 0([string "Alias: "]:1: unexpected symbol near `<'). What do you mean when you say 'if I run this'? run it where and run it how. | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #6 on Mon 18 Dec 2006 03:40 AM (UTC) |
Message
| I am assuming you downloaded version 3.83 as I indicated it was needed.
Please read this post:
http://www.gammon.com.au/forum/?id=4777
Apart from editing the match string, the rest should have been unchanged. It sounds like you were sending to the MUD, not send to script. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Burzmali
(10 posts) Bio
|
Date
| Reply #7 on Mon 18 Dec 2006 08:40 AM (UTC) |
Message
| Thanks Mr Gammon. The cut paste worked and strangely enough that little action helped a whole lot of other things come into focus as well. I have successfully implemented your suggestions and everything is working great. I did run into 1 small hurdle. The mud i am on (or Mush or Lua) is outputing TriggerStyleRuns [3].text (which strangley enough did turn out to be the one i needed) as a fixed length string of 22 char. As a result i had to test if .text == "Avoidance " instead of "Avoidance". Is there a wildcard or something that would allow for a way to pad the string out to 22 char when you dont know how many letters are in the actual string (without blanks)?
Thanks again - awsome system you have developed
| Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #8 on Mon 18 Dec 2006 07:10 PM (UTC) |
Message
| Instead of testing:
if blah.text == "Avoidance " then
...
end -- if
... you can use a regular expression to look for zero or more trailing spaces:
if string.match (blah.text, "^Avoidance%s*$") then
...
end -- if
If there might be leading spaces you can use %s at the start too:
if string.match (blah.text, "^%s*Avoidance%s*$") then
...
end -- if
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Fletchling
Australia (54 posts) Bio
|
Date
| Reply #9 on Wed 20 Dec 2006 09:50 PM (UTC) |
Message
| Hi ho Burzmali,
It looks like you are playing a mud like Aardwolf and trying to create a spellup script. IF that is correct there are other ways to let mush know if the spell is active (and therefore needs to be recast). If true, I'm happy to post my Aardwolf spellup script for you to examine.
Fletchling (aka Cuddlepie) | Top |
|
Posted by
| Burzmali
(10 posts) Bio
|
Date
| Reply #10 on Thu 21 Dec 2006 08:03 PM (UTC) |
Message
| Yes Fletchling that would be helpful. I have what i wanted to work working thanks to the help I got here (thanks again Mr Gammon) but I am sure that seeing what you have would help me get a better handle on how all this stuff works. | 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.
28,691 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top