I am trying to match my public channel aliases to match my custom item strings, they basically look like this |r[|R[|Dword |wword |Wword |wword |Dword|R]|r]. The gray to white gradient them would be the changing text. I tried using a simple alias but using *s and %s doesn't work. How would I write a script so that it divides the text I enter by 5 and places it accordingly so that it follows the gradient scale? I've never written or used a script before, and I looked all over in the forums for something similar with no prevail. Any assistance would be greatly appreciated.
script for gradient scale colors in public channels?
Posted by Yup on Sat 31 May 2014 03:54 PM — 12 posts, 49,516 views.
Yup said:
How would I write a script so that it divides the text I enter by 5 and places it accordingly so that it follows the gradient scale?
How would I write a script so that it divides the text I enter by 5 and places it accordingly so that it follows the gradient scale?
Can you post your current alias?
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
Quote:
... they basically look like this ...
... they basically look like this ...
Also copy and paste actual output.
I don't currently have an alias for it, other than the simple in game alias, I was using ct * * * * *, then clan talk |r[|R[|D%1 |w%2 |W%3 |w%4 |D%5|R]|r]. but that doesn't work. With less than 5 words, the alias doesn't work, with more than 5 words it won't separate the colors accordingly, it just leaves them gray at the end. Hope this helps, thank you for your response. I redid the alias I had before, this is what copying it looks like.
<aliases>
<alias
match="ct * * * * *"
enabled="y"
send_to="10"
sequence="100"
>
<send>clan talk |r[|R[|D%1 |w%2 |W%3 |w%4 |D%5|R]|r]</send>
</alias>
</aliases>
<aliases>
<alias
match="ct * * * * *"
enabled="y"
send_to="10"
sequence="100"
>
<send>clan talk |r[|R[|D%1 |w%2 |W%3 |w%4 |D%5|R]|r]</send>
</alias>
</aliases>
What I think he wants (and isn't explaining real well) is to recolor all of his input on a gradient color scale with shifts every 20% of the text string. The good news is, if anyone can script that, it's Nick. The bad news is, it's some seriously nontrivial stuff and you aren't going to be able to do a simply 5 wildcard match.
This will colour each word differently:
What this does is use string.gmatch to break up what you typed (%1) into groups of non-blank things (ie. words). Then it puts the colours from the colours table in front of each one (thus you can change the table to have different colours, or more of them).
If you get more than five words it cycles back to the first colour (add more colours to the table to extend that).
This example assumes you are using Lua scripting as your scripting language (which is the default).
<aliases>
<alias
match="ct *"
enabled="y"
send_to="12"
sequence="100"
>
<send>
-- first part
local result = "clan talk |r[|R["
-- table of colours
local colours = { "D", "w", "W", "w", "D" }
-- start at first one
local i = 1
-- now do each word with a different colour prefix
for word in string.gmatch ("%1", "%%S+") do
result = result .. "|" .. colours [i] .. word .. " "
i = i + 1 -- next colour
-- wrap around after all colours used
if i > #colours then
i = 1
end -- if
end -- for
-- send finished line
Send (result .. "|R]|r]")
</send>
</alias>
</aliases>
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
What this does is use string.gmatch to break up what you typed (%1) into groups of non-blank things (ie. words). Then it puts the colours from the colours table in front of each one (thus you can change the table to have different colours, or more of them).
If you get more than five words it cycles back to the first colour (add more colours to the table to extend that).
This example assumes you are using Lua scripting as your scripting language (which is the default).
I tried it, once there are too many words in the message it generates too many color codes. Is there a way to cap this to 5 different colors inside the [[ ]]? Also, it adds a space at the end of the message before the ]].
like this:
[7] clan members heard you say, '[[how does this work ]]'
Thank you for your continued assistance.
like this:
[7] clan members heard you say, '[[how does this work ]]'
Thank you for your continued assistance.
You can get rid of the space with Trim (as shown). I have modified it a bit to stop adding colours after they are all used up:
<aliases>
<alias
match="ct *"
enabled="y"
send_to="12"
sequence="100"
>
<send>
-- first part
local result = "clan talk |r[|R["
-- table of colours
local colours = { "D", "w", "W", "w", "D" }
-- start at first one
local i = 1
-- now do each word with a different colour prefix
for word in string.gmatch ("%1", "%%S+") do
if i <= #colours then
result = result .. "|" .. colours [i] .. word .. " "
i = i + 1 -- next colour
else
result = result .. word .. " "
end -- if
end -- for
-- send finished line
Send (Trim (result) .. "|R]|r]")
</send>
</alias>
</aliases>
Now it changes the first 5 words to the right colors, and remains gray at the end?
Well, what code is gray?
Using that alias, if I type:
I get:
So the last few words are in the "D" colour.
Using that alias, if I type:
ct aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii
I get:
clan talk |r[|R[|Daaaa |wbbbb |Wcccc |wdddd |Deeee ffff gggg hhhh iiii|R]|r]
So the last few words are in the "D" colour.
Yup, the last batch of words stay gray, it doesn't divide them out evenly:
I get:
clan talk |r[|R[|Daaaa |wbbbb |Wcccc |wdddd |Weeee ffff gggg hhhh iiii jjjj|R]|r]
It should look like:
clan talk |r[|R[|Daaaa bbbbb |wcccc dddd |Weeeee fffff |wgggg hhhh |Wiiii jjjjjj|R]|r]
so that the gradient scheme follows all the way to the last word. I would settle for this way, if it's too much work. I know it's probably a complicated script for something so trivial. Someone said that, in order to do this I'd have to script an arithmetic to divide the number of words by 5, then set each to a unique variable, then change the colors of each variable accordingly?
I get:
clan talk |r[|R[|Daaaa |wbbbb |Wcccc |wdddd |Weeee ffff gggg hhhh iiii jjjj|R]|r]
It should look like:
clan talk |r[|R[|Daaaa bbbbb |wcccc dddd |Weeeee fffff |wgggg hhhh |Wiiii jjjjjj|R]|r]
so that the gradient scheme follows all the way to the last word. I would settle for this way, if it's too much work. I know it's probably a complicated script for something so trivial. Someone said that, in order to do this I'd have to script an arithmetic to divide the number of words by 5, then set each to a unique variable, then change the colors of each variable accordingly?
If I may suggest, why not try to do it yourself? The experience you gain will help you in future situations.
You could indeed put the words into a table. Details about tables here:
http://www.gammon.com.au/forum/?id=4903
and here:
http://www.gammon.com.au/forum/?id=6036
You could find how many items are in the table and then divide that by 5.
Then output the appropriate parts of the table with the appropriate colours.
You could indeed put the words into a table. Details about tables here:
http://www.gammon.com.au/forum/?id=4903
and here:
http://www.gammon.com.au/forum/?id=6036
You could find how many items are in the table and then divide that by 5.
Then output the appropriate parts of the table with the appropriate colours.
Thank you, very much. I have already learned a lot, and it will be very useful in the future.