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.

Non-existent list

Discussion in 'Skript' started by Aerosmite, Feb 13, 2017.

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

    Aerosmite New Member

    Joined:
    Jan 27, 2017
    Messages:
    9
    Likes Received:
    2
    Hi ! My problem is simple. I have a function that test if a player is in a list and return true or false. But when I input a non-existent list, it just responds "<none>" but I need a false return. What can I do ?
    Code (Skript):
    1. function PlayerIsInList(p: player,players: strings) :: boolean:
    2.     if {_players::*} is set:
    3.         loop {_players::*}:
    4.             set {_check::*} to groups 0 of loop-value matched to "^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$"
    5.             if {_check::1} is set:
    6.                 set {_players::%loop-index%} to player from "%loop-value%"
    7.                 clear {_check::*}
    8.             if "%{_players::%loop-index%}%" is "%{_p}%":
    9.                 return true
    10.                 stop
    11.     return false
     
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    225
    you dont use {} here but at
    you do. i think thats the problem

    so use %{_players}%
     
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    225
    No there is no problem here, I don't think I made a mistake in my syntaxe it must be in my algorythm

    I should try to simplify the problem:
    I want this function to return false when I input a non-existent list.
    Code (Skript):
    1. function Playerstest(players: strings) :: boolean:
    2.     if {_players::*} is set:
    3.         return true
    4.     else:
    5.         return false
     
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    225
    The function looks alright to me.

    Might be an issue with the code that's using the function, since the function itself does not send or return any text

    It should be used like this:
    Code (Skript):
    1.  
    2. command /testfunc:
    3.   trigger:
    4.     set {_bool} to PlayerIsInList(player, all players)
    5.     send "Should be true: &a%{_bool}%" #Debug
    6.     if {_bool} is true:
    7.       send "&aPlayer was on the list (should output this)"
    8.     else:
    9.       send "&cPlayer was not on the list (it shouldn't have outputted this; what happened?)"
    10.    
    11.     set {_list::*} to all players
    12.     remove player from {_list::*}
    13.     set {_bool} to PlayerIsInList(player, {_list::*})
    14.     send "Should be false: &a%{_bool}%"
    15.     if {_bool} is true:
    16.       send "&cPlayer was on the list (it shouldn't have outputted this; what happened?"
    17.     else:
    18.       send "&aPlayer was not on the list (should output this)"
    19.  
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    225
    • Agree Agree x 1
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    225
    This will work fine yes, but if I add this to your code:
    Code (Skript):
    1.     set {_bool} to PlayerIsInList(player, {_empty::*})
    2.     send "Should be false: &a%{_bool}%"
    3.     if {_bool} is true:
    4.       send "&cPlayer was on the list (it shouldn't have outputted this; what happened?"
    5.     else if {_bool} is false:
    6.       send "&aPlayer was not on the list (should output this)"
    7.     else:
    8.       send "&cReturn nothing, what happened ?"
     
Thread Status:
Not open for further replies.

Share This Page

Loading...