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 Efficiency regarding functions

Discussion in 'Skript' started by Wynnevir, Jan 3, 2018.

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

    Wynnevir Well-Known Member

    Joined:
    Jul 9, 2017
    Messages:
    1,015
    Likes Received:
    62
    I just had a question about functions inside of other functions. If I have repetitive action within a current function, is it more efficient or useless to make those functions as well? Currently for me it's just a lot of messaging for different outcomes based on perms, but in general?

    EDIT: This is the code I'm using. No issue with it or anything, I just want to know if having so many functions like this is benefiting me or not^-^ I'm trying to get more efficient
    Code (Skript):
    1. function homeMsg(p: player, t: text):
    2.     set {homes::%{_p}%::%{_t}%} to location of {_p}
    3.     send "&e&l[&b&l✔&e&l] &r&7Home &l%{_t}% &7 set to %{homes::%{_p}%::%{_t}%}%"
    4. #--------------------------------
    5. function sizeMsg(p: player):
    6.     send "&e&l[&d&l✖&e&l] &r&7Home limit reached. Delete a home to set a new one" to {_p}
    7.     stop  
    8. #--------------------------------
    9. function setHome(p: player, t: text):      
    10.     loop {homes::%{_p}%::*}:
    11.         if loop-index = {_t}:
    12.             send "home name already exists." to {_p}
    13.             stop
    14.     if {_p} has permission "unlim.homes":
    15.         homeMsg({_p}, {_t})
    16.     else if {_p} has permission "10.homes":
    17.         if size of {homes::%{_p}%::*} = 10:
    18.             sizeMsg({_p})
    19.         homeMsg({_p}, {_t})
    20.     else if {_p} has permission "5.homes":
    21.         if size of {homes::%{_p}%::*} = 5:
    22.             sizeMsg({_p})
    23.         homeMsg({_p}, {_t})
    24.     else if {_p} has permission "4.homes":
    25.         if size of {homes::%{_p}%::*} = 4:
    26.             sizeMsg({_p})
    27.         homeMsg({_p}, {_t})
    28.     else if {_p} has permission "3.homes":
    29.         if size of {homes::%{_p}%::*} = 3:
    30.             sizeMsg({_p})
    31.         homeMsg({_p}, {_t})
    32.     else if {_p} has permission "1.homes":
    33.         if size of {homes::%{_p}%::*} = 1:
    34.             sizeMsg({_p})
    35.         homeMsg({_p}, {_t})
     
    #1 Wynnevir, Jan 3, 2018
    Last edited: Jan 3, 2018
  2. Best Answer:
    Post #2 by Syst3ms, Jan 3, 2018
  3. Syst3ms

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    191
    Likes Received:
    22
    The question here is not about how efficient functions are, the lag is pretty much neglectable.
    Are you going to use the code that's inside the function more than times? Then keep it.
    Otherwise, it's the code in the function pretty long? Keep it too then.
     
  4. Wynnevir

    Wynnevir Well-Known Member

    Joined:
    Jul 9, 2017
    Messages:
    1,015
    Likes Received:
    62
    Okay, thanks for clearing that up for me!:emoji_grinning:
     
  5. Pikachu

    Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    870
    Likes Received:
    139
    Medals:
    I recommend using skript-mirror like this for this purpose:
    Code (Skript):
    1. get expression size message:
    2.   continue returning "&e&l[&d&l✖&e&l] &r&7Home limit reached. Delete a home to set a new one"
    then
    Code (Skript):
    1. send size message to player
     
  6. Syst3ms

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    191
    Likes Received:
    22
    Or options, you know, the feature that's been intended for this purpose ?
     
  7. Wynnevir

    Wynnevir Well-Known Member

    Joined:
    Jul 9, 2017
    Messages:
    1,015
    Likes Received:
    62
    Would options be better than a function? It seems like you said, on this scale the lag is negligible, but just best case scenario?
     
  8. Syst3ms

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    191
    Likes Received:
    22
    The lag is negligible, but you know, that's not a reason to not use a feature that's been intended for this exact purpose.
    Plus, I don't know how you can beat something that's replaced before parsing in terms of performance.
     
  9. Pikachu

    Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    870
    Likes Received:
    139
    Medals:
    Expressions are just more versatile
     
  10. Syst3ms

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    191
    Likes Received:
    22
    Functions are very versatile too, that doesn't mean I should replace the send message effect with one.
    Seriously you guys need to calm down with skript-mirror custom syntax.
     
  11. Snow-Pyon

    Snow-Pyon Well-Known Member

    Joined:
    Jan 25, 2017
    Messages:
    1,235
    Likes Received:
    176
    Medals:
    I agree with @Syst3ms here, an option would be just fine.
     
  12. Pikachu

    Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    870
    Likes Received:
    139
    Medals:
    I mean compared to options
     
Thread Status:
Not open for further replies.

Share This Page

Loading...