Element of a list variable

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

iChinchillinq

Member
May 11, 2018
10
0
0
22
I'm making a Cards Against Humanity skript atm, and all of the "second, third, fourth, etc" elements aren't working. However, the first element works.

code_language.skript:
                if argument 1 is "pick":
                    if argument 2 is not set:
                        send "&5CAH &8» &fPlease pick a valid card. (Numbers 1-10)"
                    else:
                        if argument 2 is "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9" or "10":                         
                            set {picked.%player%} to argument 2
                            if argument 2 is "1":
                                set {card.%player%} to the first element of {cards.%player%::*}
                            if argument 2 is "2":
                                set {card.%player%} to the second element of {cards.%player%::*}
                            if argument 2 is "3":
                                set {card.%player%} to the third element of {cards.%player%::*}
                            if argument 2 is "4":
                                set {card.%player%} to the fourth element of {cards.%player%::*}
                            if argument 2 is "5":
                                set {card.%player%} to the fifth element of {cards.%player%::*}
                            if argument 2 is "6":
                                set {card.%player%} to the sixth element of {cards.%player%::*}
                            if argument 2 is "7":
                                set {card.%player%} to the seventh element of {cards.%player%::*}
                            if argument 2 is "8":
                                set {card.%player%} to the eighth element of {cards.%player%::*}
                            if argument 2 is "9":
                                set {card.%player%} to the ninth element of {cards.%player%::*}
                            if argument 2 is "10":
                                set {card.%player%} to the tenth element of {cards.%player%::*}
                            send "&5CAH &8» &fPicked card &d%{picked.%player%}%&f.%nl%&f(%{card.%player%}%)"

Errors: http://prntscr.com/k98g8s
 
I think you could also use
code_language.skript:
{cards.%player%::%arg 2%}

Like
code_language.skript:
arg 2 is not set:

  send "&5CAH &8» &fPlease pick a valid card. (Numbers 1-10)"
  stop

arg 2 = "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9" or "10"
send "&5CAH &8» &fPicked card &d%arg 2%&f.%nl%&f(%{cards.%player%::%arg 2%}%)"
 
I think you could also use
code_language.skript:
{cards.%player%::%arg 2%}

Like
code_language.skript:
arg 2 is not set:

  send "&5CAH &8» &fPlease pick a valid card. (Numbers 1-10)"
  stop

arg 2 = "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9" or "10"
send "&5CAH &8» &fPicked card &d%arg 2%&f.%nl%&f(%{cards.%player%::%arg 2%}%)"
1. Use list variables (replace all ' . ' with ' :: '), its a way easier/clean way to save vars

2. Use else if after an if, like this: (Less laggy)
code_language.skript:
if arg-1 = "1":
    send "1"
else if arg-1 = "2":
    send "2"

And @FinalPlayer024 is right, since it's better to use {cards::%player%::4}

Full code:
code_language.skript:
                if arg-1 is "pick":
                    if arg-2 is not set:
                        send "&5CAH &8» &fPlease pick a valid card. (Numbers 1-10)"
                    else:
                        if arg-2 is "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9" or "10":                    
                            set {picked::%player%} to arg-2
                            set {card::%player%} to {cards::%player%::%arg-2%}
                            send "&5CAH &8» &fPicked card &d%{picked::%player%}%&f.%nl%&f(%{card::%player%}%)"
 
Last edited:
1. Use list variables (replace all ' . ' with ' :: '), its a way easier/clean way to save vars

2. Use else if after an if, like this: (Less laggy)
code_language.skript:
if arg-1 = "1":
    send "1"
else if arg-1 = "2":
    send "2"

And @FinalPlayer024 is right, since it's better to use {cards::%player%::4}

Full code:
code_language.skript:
                if arg-1 is "pick":
                    if arg-2 is not set:
                        send "&5CAH &8» &fPlease pick a valid card. (Numbers 1-10)"
                    else:
                        if arg-2 is "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9" or "10":                      
                            set {picked::%player%} to arg-2
                            if arg-2 is "1":
                                set {card::%player%} to {cards::%player%::1}
                            else if arg-2 is "2":
                                set {card::%player%} to {cards::%player%::2}
                            else if arg-2 is "3":
                                set {card::%player%} to {cards::%player%::3}
                            else if arg-2 is "4":
                                set {card::%player%} to {cards::%player%::4}
                            else if arg-2 is "5":
                                set {card::%player%} to {cards::%player%::5}
                            else if arg-2 is "6":
                                set {card::%player%} to {cards::%player%::6}
                            else if arg-2 is "7":
                                set {card::%player%} to {cards::%player%::7}
                            else if arg-2 is "8":
                                set {card::%player%} to {cards::%player%::8}
                            else if arg-2 is "9":
                                set {card::%player%} to {cards::%player%::9}
                            else if arg-2 is "10":
                                set {card::%player%} to {cards::%player%::10}
                            send "&5CAH &8» &fPicked card &d%{picked::%player%}%&f.%nl%&f(%{card::%player%}%)"
Look at the code again. It can be done much easier...
 
for future reference to get the nth element of a list (besides first/last) you have to use the number like 3rd, 4th, 5th, 80th, 100th as the syntax is
code_language.skript:
([the] first|[the] last|[a] random|%number%(st|nd|rd|th)) element [out] of %objects%
 
Status
Not open for further replies.