Solved "return" in function

  • 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!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

glowgrew

Active Member
Jan 26, 2017
99
7
0
Perm, Russia
Hello. I have a function:
code_language.skript:
function ColorRandomizer(v1: text, v2: text, v3: player) :: text:
    add "&a" to {_c::*}
    add "&b" to {_c::*}
    add "&c" to {_c::*}
    add "&d" to {_c::*}
    add "&e" to {_c::*}
    add "&6" to {_c::*}
    add "&3" to {_c::*}
    add "&2" to {_c::*}
    add "&5" to {_c::*}
    set {_api%{_v1}%%{_v2}%%{_v3}%} to a random element out of {_c::*}
    set {_api%{_v1}%%{_v2}%%{_v3}%} to {_api}
    return {_api}
When I'm calling the function in my code with
code_language.skript:
ColorRandomizer("a", "%script%", player)
send "%{_api}%test"
It sends "<none>". @ImOfflinezzz, объясни ты, если умеешь, а то я в этих функциях ничо не понимаю((9.
 
  • Like
Reactions: ImOfflinezzz
Where I have to paste it in?
code_language.skript:
function ColorRandomizer(t: text == "") :: text:
    add "&a" to {_c::*}
    add "&b" to {_c::*}
    add "&c" to {_c::*}
    add "&d" to {_c::*}
    add "&e" to {_c::*}
    add "&6" to {_c::*}
    add "&3" to {_c::*}
    add "&2" to {_c::*}
    add "&5" to {_c::*}
    set {_api} to a random element out of {_c::*}
    return {_api}

command /cmd:
    trigger:
        set {_api} to ColorRandomizer()
        send "%{_api}%test"
 
code_language.skript:
function ColorRandomizer(t: text == "") :: text:
    add "&a" to {_c::*}
    add "&b" to {_c::*}
    add "&c" to {_c::*}
    add "&d" to {_c::*}
    add "&e" to {_c::*}
    add "&6" to {_c::*}
    add "&3" to {_c::*}
    add "&2" to {_c::*}
    add "&5" to {_c::*}
    set {_api} to a random element out of {_c::*}
    return {_api}

command /cmd:
    trigger:
        set {_api} to ColorRandomizer()
        send "%{_api}%test"
Sends <none> :/
 
That function can be shortned, actually:
code_language.skript:
function colorRandomizer(text: text = "") :: text:

    set {_colors::*} to 2, 3, 5, 6, "a", "b", "c", "d" and "e"
  
    return "&%random element out of {_colors::*}%"
And because I was bored, here a function:

code_language.skript:
function colorRandomizer(text: text) :: text:

    set {_colors::*} to 2, 3, 5, 6, "a", "b", "c", "d" and "e"
    set {_text-chars::*} to split {_text} by ""
    set {_color-replace::*} to {_colors::*}
 
    loop {_text-chars::*}:
     
        if length of {_text} is greater than size of {_colors::*}:
            set {_color-replace::*} to {_colors::*} and {_colors::*}
     
        set {_random-color} to random element out of {_color-replace::*}
        remove {_random-color} from {_color-replace::*}
        set {_text-chars::%loop-index%} to "&%{_random-color}%%loop-value%"
 
    return colored join {_text-chars::*} by ""
 
Status
Not open for further replies.