Skript Function Help return not working?

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

Tristag

Member
Jan 26, 2017
14
0
0
33
code_language.skript:
function nameCheck(p: player) :: number:

    send a request to "https://api.mojang.com/users/profiles/minecraft/%{_p}%"
   
    return 1
   
    if the body of last http response parsed as text contains "id":
        stop

command /namecheck2:
    trigger:
        if nameCheck(player) is 1:
            broadcast "true"

So this one doesn't work... the return seems to turn into nothing.

code_language.skript:
function nameCheck(p: player) :: number:

    return 1
   
    send a request to "https://api.mojang.com/users/profiles/minecraft/%{_p}%"
   
    if the body of last http response parsed as text contains "id":
        stop

command /namecheck2:
    trigger:
        if nameCheck(player) is 1:
            broadcast "true"

However, putting the "return 1" just one line above the send request, it works perfectly...

Can anyone explain :emoji_astonished: ?
 
"send request" delays the function a little bit, so the code in the function does not finish instantly. Therefore, it returns 1 a little bit later. But at this point the command "namecheck2" has already run "if nameCheck(player) is 1:", and found that it is not true because it did not get the result from the function.

You should never have a delay in a function that is supposed to return a value. And remember that the function stops once it executes a "return".
 
So I would need to insert a wait in the command? Or is the above impossible?

Eventually the return will be beoolean if it matters, this was the simplest example I could think of at the time. I'm planning on using a function to make sure a player is real :emoji_slight_smile:
 
Status
Not open for further replies.