Second to last item in 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.
Apr 22, 2020
48
4
8
I know this is possible:

Code:
set {_last} to the last element out of {_list::*}

But I need someway of getting the last 40 items in a list?
Maybe second to last?
Code:
set {_second_to_last} to the second to last element out of {_list::*}

Code:
set {_list2::*} to the last 40 elements out of {_list::*}
 
I know this is possible:

Code:
set {_last} to the last element out of {_list::*}

But I need someway of getting the last 40 items in a list?
Maybe second to last?
Code:
set {_second_to_last} to the second to last element out of {_list::*}

Code:
set {_list2::*} to the last 40 elements out of {_list::*}

Getting second to last element in list (https://skripthub.net/docs/?id=942)
code_language.skript:
set {_element} to the (size of {_list::*} - 1)th element out of {_list::*}

Getting last 40 elements of a list (Not tested, would recommend adding some conditions)
code_language.skript:
set {_s} to size of {_list::*}
loop 40 times:
    add the {_s}th element out of {_list::*} to {_list2::*}
    subtract 1 from {_s}
set {_list2::*} to reversed {_list2::*} # This line requires Skript 2.4+
 
Last edited:
Getting second to last element in list (https://skripthub.net/docs/?id=942)
code_language.skript:
set {_element} to the (size of {_list::*} - 1)th element out of {_list::*}

Getting last 40 elements of a list (Not tested, would recommend adding some conditions)
code_language.skript:
set {_s} to size of {_list::*}
loop 40 times:
    add the {_s}th element out of {_list::*} to {_list2::*}
    subtract 1 from {_s}
set {_list2::*} to reversed {_list2::*} # This line requires Skript 2.4+

Sadly this:
Code:
add the {_s}th element out of {_list::*} to {_list2::*}
Will not work as this is what skript will see and it can't understand 23th element.
Code:
add the 23th element out of {_list::*} to {_list2::*}
 
Status
Not open for further replies.