Solved Efficiency regarding functions

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

Wynnevir

Well-Known Member
Jul 9, 2017
1,015
62
48
30
Elsewhere
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_language.skript:
function homeMsg(p: player, t: text):
    set {homes::%{_p}%::%{_t}%} to location of {_p}
    send "&e&l[&b&l✔&e&l] &r&7Home &l%{_t}% &7 set to %{homes::%{_p}%::%{_t}%}%"
#--------------------------------
function sizeMsg(p: player):
    send "&e&l[&d&l✖&e&l] &r&7Home limit reached. Delete a home to set a new one" to {_p}
    stop   
#--------------------------------
function setHome(p: player, t: text):       
    loop {homes::%{_p}%::*}:
        if loop-index = {_t}:
            send "home name already exists." to {_p}
            stop
    if {_p} has permission "unlim.homes":
        homeMsg({_p}, {_t})
    else if {_p} has permission "10.homes":
        if size of {homes::%{_p}%::*} = 10:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
    else if {_p} has permission "5.homes":
        if size of {homes::%{_p}%::*} = 5:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
    else if {_p} has permission "4.homes":
        if size of {homes::%{_p}%::*} = 4:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
    else if {_p} has permission "3.homes":
        if size of {homes::%{_p}%::*} = 3:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
    else if {_p} has permission "1.homes":
        if size of {homes::%{_p}%::*} = 1:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
 
Last edited:
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.
 
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.
Okay, thanks for clearing that up for me!:emoji_grinning:
 
I recommend using skript-mirror like this for this purpose:
code_language.skript:
get expression size message:
  continue returning "&e&l[&d&l✖&e&l] &r&7Home limit reached. Delete a home to set a new one"
then
code_language.skript:
send size message to player
 
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.
 
Expressions are just more versatile
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.
 
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.
I mean compared to options
 
Status
Not open for further replies.