Shane's Expressions (Rainbow Text/words)(String of random Char)

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

ShaneBee

Supporter +
Addon Developer
Sep 7, 2017
2,247
241
73
Vancouver, Canada
So I made an expression for rainbow text/words (Uses Skript-Mirror) and also did the same thing in a function (for those that dont want to use Skript-Mirror.
Just added an expression to create a string of random characters

Expression:
code_language.skript:
#!EXPRESSION -- Rainbow Words / Letters in text
expression rainbow [(1¦word[s]|2¦letter[s])] %string%:
    get:
        if parse mark is 1 or 0:
            set {_col::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"
            set {_newcol::*} to {_col::*}
            set {_text::*} to expression-1 split at " "
            loop {_text::*}:
                if loop-value is not " ":
                    if {_newcol::*} is not set:
                        set {_newcol::*} to {_col::*}
                    set {_col} to first element of {_newcol::*}
                    set {_newword::%loop-index%} to "%{_col}%%loop-value%"
                    remove {_col} from {_newcol::*}
                else:
                    set {_newword::%loop-index%} to loop-value
            set {_newword} to join {_newword::*} with " "
            return {_newword}
        else if parse mark is 2:
            set {_col::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"
            set {_newcol::*} to {_col::*}
            set {_text::*} to expression-1 split at ""
            loop {_text::*}:
                if loop-value is not " ":
                    if {_newcol::*} is not set:
                        set {_newcol::*} to {_col::*}
                    set {_col} to first element of {_newcol::*}
                    set {_newword::%loop-index%} to "%{_col}%%loop-value%"
                    remove {_col} from {_newcol::*}
                else:
                    set {_newword::%loop-index%} to loop-value
            set {_newword} to join {_newword::*} with ""
            return {_newword}
code_language.skript:
#! Function for individually colored letters
function rainbowLetters(t: text) :: text:
    set {_col::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"
    set {_newcol::*} to {_col::*}
    set {_text::*} to {_t} split at ""
    loop {_text::*}:
        if loop-value is not " ":
            if {_newcol::*} is not set:
                set {_newcol::*} to {_col::*}
            set {_col} to first element of {_newcol::*}
            set {_newword::%loop-index%} to "%{_col}%%loop-value%"
            remove {_col} from {_newcol::*}
        else:
            set {_newword::%loop-index%} to loop-value
    set {_newword} to join {_newword::*} with ""
    return {_newword}
 
#! Function for colored words
function rainbowWord(t: text) :: text:
    set {_col::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"
    set {_newcol::*} to {_col::*}
    set {_text::*} to {_t} split at " "
    loop {_text::*}:
        if loop-value is not " ":
            if {_newcol::*} is not set:
                set {_newcol::*} to {_col::*}
            set {_col} to first element of {_newcol::*}
            set {_newword::%loop-index%} to "%{_col}%%loop-value%"
            remove {_col} from {_newcol::*}
        else:
            set {_newword::%loop-index%} to loop-value
    set {_newword} to join {_newword::*} with " "
    return {_newword}
[doublepost=1535059791,1534929763][/doublepost]Thanks to @KingAlterIV for changing one line in this.... which speeds up the expression/function quiet a bit. Based on my testing it's about 8 times faster.

code_language.skript:
#! SYNTAX
random string of %integer% [capital[ized]] character[s]

#! EXPRESSION - Random string of letters
expression random string of %integer% [(1¦capital[ized])] character[s]:
    get:
        set {_let} to "abcdefghijklmnopqrstuvwxyz"
        set {_letters::*} to {_let} split at ""
        loop expression-1 times:
            add random element of {_letters::*} to {_newstring::*}
        set {_newstring} to join {_newstring::*} by ""
        if parse mark is 0:
            return {_newstring}
        if parse mark is 1:
            return capitalized {_newstring}

#! EXAMPLE
command /random <integer> [<text>]:
    trigger:
        if arg-2 is not set:
            send "&aTEST: %random string of arg-1 characters%"
        else:
            if arg-2 is "cap":
                send "&aTEST: %random string of arg-1 capital characters%"
Edited ... thanks to a suggestion by donut!
 
Last edited:
heres my go at it
code_language.skript:
on script load:
    set {rainbow::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"

function rainbowLetters(t: text) :: text:
    loop {_t} split at "":
        if loop-value is not " ": 
            set {_i} to {_i} + 1 if {_i} < 10 else 1
        set {_new} to join {_new} and {rainbow::%{_i}%} and loop-value
    return {_new}

function rainbowWord(t: text) :: text:
    loop {_t} split at " ":
        set {_i} to {_i} + 1 if {_i} < 10 else 1
        set {_new} to join {_new} and {rainbow::%{_i}%} and loop-value and " "
    return {_new}
 
  • Like
Reactions: ShaneBee
heres my go at it
code_language.skript:
on script load:
    set {rainbow::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"

function rainbowLetters(t: text) :: text:
    loop {_t} split at "":
        if loop-value is not " ":
            set {_i} to {_i} + 1 if {_i} < 10 else 1
        set {_new} to join {_new} and {rainbow::%{_i}%} and loop-value
    return {_new}

function rainbowWord(t: text) :: text:
    loop {_t} split at " ":
        set {_i} to {_i} + 1 if {_i} < 10 else 1
        set {_new} to join {_new} and {rainbow::%{_i}%} and loop-value and " "
    return {_new}
Showoff :emoji_wink: jk
[doublepost=1535584529,1535091333][/doublepost]I added an expression to create a string of random characters (All capital or not)
 
any reason in particular you're doing this
code_language.skript:
add "a" and "b" and "c" and "d" and "e" and "f" and "g" and "h" and "i" and "j" and "k" and "l" and "m"
instead of this:
code_language.skript:
add "a", "b",  "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" and "m"
? :emoji_astonished:
 
any reason in particular you're doing this
code_language.skript:
add "a" and "b" and "c" and "d" and "e" and "f" and "g" and "h" and "i" and "j" and "k" and "l" and "m"
instead of this:
code_language.skript:
add "a", "b",  "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" and "m"
? :emoji_astonished:
Well thats embarrassing :emoji_wink:
For some dumb reason I thought you had to use the AND.... I will make the change
Also if you are wondering why i broke it up into 2 lines, it was strictly just to make it so my skript file wasn't 4 feet wide on my screen :emoji_wink:
 
btw you can do
code_language.skript:
set {_letters::*} to "abcdefghijklmnopqrstuvwxyz" split at ""

also im sorry i dont mean to rain on your parade but i cant help myself to point out alternatives:
code_language.skript:
import:
    org.apache.commons.lang3.RandomStringUtils

expression random string of %integer% [(1¦capital[ized])] character[s]:
    get:
        return RandomStringUtils.randomAlphabetic(expr-1) in lower case if parse mark is 0 else capitalized RandomStringUtils.randomAlphabetic(expr-1)
 
  • Like
Reactions: ShaneBee
btw you can do
code_language.skript:
set {_letters::*} to "abcdefghijklmnopqrstuvwxyz" split at ""

also im sorry i dont mean to rain on your parade but i cant help myself to point out alternatives:
code_language.skript:
import:
    org.apache.commons.lang3.RandomStringUtils

expression random string of %integer% [(1¦capital[ized])] character[s]:
    get:
        return RandomStringUtils.randomAlphabetic(expr-1) in lower case if parse mark is 0 else capitalized RandomStringUtils.randomAlphabetic(expr-1)
Hahah no need to apologize
"set {_letters::*} to "abcdefghijklmnopqrstuvwxyz" split at """ <---WELL FRIGGEN HELL that just makes it like 1,000,000 cleaner. Thanks
Part #2... OOF... ok So clearly you're a lot better at Java/Skript mirror than I am :emoji_wink:
 
hey you're welcome. we're in this together... this mission to shorten lines of code x)
I'll also get in:
code_language.skript:
on script load:

  set {colors::*} to split "0123456789abcdef" by ""

function rainbowLetters(input: texts) :: texts:
  loop {_input::*}:
    set {_input} to split loop-value by ""
    set {_color} to random element out of
    loop {_input} split by "":
      set {_color} to random element out of ({colors::*} where [input isn't {_color}]
      set {_output} to join {_output}, "<%{_color}%>" and loop-value by ""
    add {_output} to {_final::*}
  return {_final::*}
It can be a lot shorter if I were to use addons such as MundoSK, skQuery or skript-mirror (I can make it a single line with skript-mirror lol) but decided to make it pure vanilla.
 
  • Like
Reactions: ShaneBee
I'll also get in:
code_language.skript:
on script load:

  set {colors::*} to split "0123456789abcdef" by ""

function rainbowLetters(input: texts) :: texts:
  loop {_input::*}:
    set {_input} to split loop-value by ""
    set {_color} to random element out of
    loop {_input} split by "":
      set {_color} to random element out of ({colors::*} where [input isn't {_color}]
      set {_output} to join {_output}, "<%{_color}%>" and loop-value by ""
    add {_output} to {_final::*}
  return {_final::*}
It can be a lot shorter if I were to use addons such as MundoSK, skQuery or skript-mirror (I can make it a single line with skript-mirror lol) but decided to make it pure vanilla.
I like your use of "set {colors::*} to split "0123456789abcdef" by """ for the colors, very smart!

64Dno01.png