[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  script for gradient scale colors in public channels?

script for gradient scale colors in public channels?

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Yup   (6 posts)  [Biography] bio
Date Sat 31 May 2014 03:54 PM (UTC)

Amended on Sun 01 Jun 2014 02:01 AM (UTC) by Yup

Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 01 Jun 2014 06:38 AM (UTC)
Message
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?


Can you post your current alias?

Template:copying 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 ...


Also copy and paste actual output.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Yup   (6 posts)  [Biography] bio
Date Reply #2 on Mon 02 Jun 2014 09:18 PM (UTC)

Amended on Mon 02 Jun 2014 09:21 PM (UTC) by Yup

Message
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>
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #3 on Mon 02 Jun 2014 10:40 PM (UTC)
Message
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.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 02 Jun 2014 11:20 PM (UTC)

Amended on Mon 02 Jun 2014 11:26 PM (UTC) by Nick Gammon

Message
This will colour each word differently:


<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 &gt; #colours then
    i = 1
  end -- if
end -- for

-- send finished line
Send (result .. "|R]|r]")

</send>
  </alias>
</aliases>



Template:pasting 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).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Yup   (6 posts)  [Biography] bio
Date Reply #5 on Tue 03 Jun 2014 01:11 AM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Tue 03 Jun 2014 03:48 AM (UTC)
Message
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 &lt;= #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>

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Yup   (6 posts)  [Biography] bio
Date Reply #7 on Tue 03 Jun 2014 03:56 AM (UTC)
Message
Now it changes the first 5 words to the right colors, and remains gray at the end?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Tue 03 Jun 2014 06:36 AM (UTC)
Message
Well, what code is gray?

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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Yup   (6 posts)  [Biography] bio
Date Reply #9 on Wed 04 Jun 2014 04:23 AM (UTC)

Amended on Wed 04 Jun 2014 05:04 AM (UTC) by Yup

Message
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?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Wed 04 Jun 2014 05:32 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Yup   (6 posts)  [Biography] bio
Date Reply #11 on Wed 04 Jun 2014 05:40 AM (UTC)
Message
Thank you, very much. I have already learned a lot, and it will be very useful in the future.
[Go to top] 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.


32,315 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]