Non-existent list

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

Aerosmite

New Member
Jan 27, 2017
9
2
0
25
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_language.skript:
function PlayerIsInList(p: player,players: strings) :: boolean:
    if {_players::*} is set:
        loop {_players::*}:
            set {_check::*} to groups 0 of loop-value matched to "^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$"
            if {_check::1} is set:
                set {_players::%loop-index%} to player from "%loop-value%"
                clear {_check::*}
            if "%{_players::%loop-index%}%" is "%{_p}%":
                return true
                stop
    return false
 
you dont use {} here but at

you do. i think thats the problem

so use %{_players}%
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_language.skript:
function Playerstest(players: strings) :: boolean:
    if {_players::*} is set:
        return true
    else:
        return false
 
The function looks alright to me.

just responds "<none>"

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_language.skript:
command /testfunc:
  trigger:
    set {_bool} to PlayerIsInList(player, all players)
    send "Should be true: &a%{_bool}%" #Debug
    if {_bool} is true:
      send "&aPlayer was on the list (should output this)"
    else:
      send "&cPlayer was not on the list (it shouldn't have outputted this; what happened?)"
    
    set {_list::*} to all players
    remove player from {_list::*}
    set {_bool} to PlayerIsInList(player, {_list::*})
    send "Should be false: &a%{_bool}%"
    if {_bool} is true:
      send "&cPlayer was on the list (it shouldn't have outputted this; what happened?"
    else:
      send "&aPlayer was not on the list (should output this)"
 
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_language.skript:
command /testfunc:
  trigger:
    set {_bool} to PlayerIsInList(player, all players)
    send "Should be true: &a%{_bool}%" #Debug
    if {_bool} is true:
      send "&aPlayer was on the list (should output this)"
    else:
      send "&cPlayer was not on the list (it shouldn't have outputted this; what happened?)"
   
    set {_list::*} to all players
    remove player from {_list::*}
    set {_bool} to PlayerIsInList(player, {_list::*})
    send "Should be false: &a%{_bool}%"
    if {_bool} is true:
      send "&cPlayer was on the list (it shouldn't have outputted this; what happened?"
    else:
      send "&aPlayer was not on the list (should output this)"
This will work fine yes, but if I add this to your code:
code_language.skript:
    set {_bool} to PlayerIsInList(player, {_empty::*})
    send "Should be false: &a%{_bool}%"
    if {_bool} is true:
      send "&cPlayer was on the list (it shouldn't have outputted this; what happened?"
    else if {_bool} is false:
      send "&aPlayer was not on the list (should output this)"
    else:
      send "&cReturn nothing, what happened ?"
 
Status
Not open for further replies.