1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved "return" in function

Discussion in 'Skript' started by glowgrew, May 31, 2017.

Thread Status:
Not open for further replies.
  1. glowgrew

    glowgrew Active Member

    Joined:
    Jan 26, 2017
    Messages:
    99
    Likes Received:
    7
    Hello. I have a function:
    Code (Skript):
    1.  
    2. function ColorRandomizer(v1: text, v2: text, v3: player) :: text:
    3.     add "&a" to {_c::*}
    4.     add "&b" to {_c::*}
    5.     add "&c" to {_c::*}
    6.     add "&d" to {_c::*}
    7.     add "&e" to {_c::*}
    8.     add "&6" to {_c::*}
    9.     add "&3" to {_c::*}
    10.     add "&2" to {_c::*}
    11.     add "&5" to {_c::*}
    12.     set {_api%{_v1}%%{_v2}%%{_v3}%} to a random element out of {_c::*}
    13.     set {_api%{_v1}%%{_v2}%%{_v3}%} to {_api}
    14.     return {_api}
    15.  
    When I'm calling the function in my code with
    Code (Skript):
    1. ColorRandomizer("a", "%script%", player)
    2. send "%{_api}%test"
    It sends "<none>". @ImOfflinezzz, объясни ты, если умеешь, а то я в этих функциях ничо не понимаю((9.
     
    • Like Like x 1
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Code (Skript):
    1. set {_api} to ColorRandomizer("a", "%script%", player)
     
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Where I have to paste it in?
     
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Code (Skript):
    1. function ColorRandomizer(t: text == "") :: text:
    2.     add "&a" to {_c::*}
    3.     add "&b" to {_c::*}
    4.     add "&c" to {_c::*}
    5.     add "&d" to {_c::*}
    6.     add "&e" to {_c::*}
    7.     add "&6" to {_c::*}
    8.     add "&3" to {_c::*}
    9.     add "&2" to {_c::*}
    10.     add "&5" to {_c::*}
    11.     set {_api} to a random element out of {_c::*}
    12.     return {_api}
    13.  
    14. command /cmd:
    15.     trigger:
    16.         set {_api} to ColorRandomizer()
    17.         send "%{_api}%test"
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Sends <none> :/
     
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Works for me
     
  7. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Oh, yeah. I forgot about reload. :emoji_grinning:
     
  8. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    That function can be shortned, actually:
    Code (Skript):
    1. function colorRandomizer(text: text = "") :: text:
    2.  
    3.     set {_colors::*} to 2, 3, 5, 6, "a", "b", "c", "d" and "e"
    4.  
    5.     return "&%random element out of {_colors::*}%"
    And because I was bored, here a function:

    Code (Skript):
    1. function colorRandomizer(text: text) :: text:
    2.  
    3.     set {_colors::*} to 2, 3, 5, 6, "a", "b", "c", "d" and "e"
    4.     set {_text-chars::*} to split {_text} by ""
    5.     set {_color-replace::*} to {_colors::*}
    6.  
    7.     loop {_text-chars::*}:
    8.      
    9.         if length of {_text} is greater than size of {_colors::*}:
    10.             set {_color-replace::*} to {_colors::*} and {_colors::*}
    11.      
    12.         set {_random-color} to random element out of {_color-replace::*}
    13.         remove {_random-color} from {_color-replace::*}
    14.         set {_text-chars::%loop-index%} to "&%{_random-color}%%loop-value%"
    15.  
    16.     return colored join {_text-chars::*} by ""
     
Thread Status:
Not open for further replies.

Share This Page

Loading...