Solved Sorted List (with sk-mirror)

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

KingAdmin_YT

Member
May 16, 2018
44
0
6
26
code_language.skript:
import:
    java.util.ArrayList
    java.util.Collections
expression (multi[ple] replace|replacer) [(elements|values)] %texts% with %objects% in %text%:
    return type: text
    get:
        set {_text} to expr-3
        loop exprs-1:
            add 1 to {_n}
            replace all "%loop-value%" with "%{_n}th element of exprs-2%" in {_text}
        return {_text}

local expression variable %objects% in %event%:
    return type: object
    get:
        set {_name} to expr-1.getName().toString(expr-2)
        return Variables.getVariable({_name}, expr-2, expr-1.isLocal())

plural expression (1¦(top|first)|2¦(last)) %integer% (values|elements) of %objects% [formatted] as %text%:
    return type: texts
    get:
        set {_map} to variable raw exprs-2 in event
         
        set {_list} to new ArrayList({_map}.entrySet())
        {_list}.sort(Entry.comparingByValue())
     
        if parse mark = 1:
            Collections.reverse({_list})
     
        loop ...{_list}:
            add 1 to {_n}
            set {_r::%{_n}%} to replacer "<pos>", "<key>" and "<value>" with "%{_n}%", "%loop-value.getValue()%" and "%loop-value.getKey()%" in expr-3
            {_n} = expr-1
            stop loop

        return {_r::*}
Errors:
Code:
[08:15:28 INFO]: [Skript] Reloading SortedList.sk...
[08:15:28 ERROR]: The return statement can only be used in a function (SortedList.sk, line 18: return Variables.getVariable({_name}, expr-2, expr-1.isLocal())')
[08:15:28 ERROR]: Can't understand this condition/effect: {_list}.sort(Entry.comparingByValue()) (SortedList.sk, line 26: {_list}.sort(Entry.comparingByValue())')
[08:15:28 INFO]: [Skript] Encountered 2 errors while reloading SortedList.sk!

Skript version: 2.4alpha4
Server version: paper 1.14.4
Skript addons: sk-yaml and sk-mirror.

Copied from: https://github.com/SkriptLang/Skript/issues/1743

Who can fix this error?

I only added these:
Code:
import:
    java.util.ArrayList
    java.util.Collections
 
Last edited:
code_language.skript:
import:
    java.util.ArrayList
    java.util.Collections
expression (multi[ple] replace|replacer) [(elements|values)] %texts% with %objects% in %text%:
    return type: text
    get:
        set {_text} to expr-3
        loop exprs-1:
            add 1 to {_n}
            replace all "%loop-value%" with "%{_n}th element of exprs-2%" in {_text}
        return {_text}

local expression variable %objects% in %event%:
    return type: object
    get:
        set {_name} to expr-1.getName().toString(expr-2)
        return Variables.getVariable({_name}, expr-2, expr-1.isLocal())

plural expression (1¦(top|first)|2¦(last)) %integer% (values|elements) of %objects% [formatted] as %text%:
    return type: texts
    get:
        set {_map} to variable raw exprs-2 in event
        
        set {_list} to new ArrayList({_map}.entrySet())
        {_list}.sort(Entry.comparingByValue())
    
        if parse mark = 1:
            Collections.reverse({_list})
    
        loop ...{_list}:
            add 1 to {_n}
            set {_r::%{_n}%} to replacer "<pos>", "<key>" and "<value>" with "%{_n}%", "%loop-value.getValue()%" and "%loop-value.getKey()%" in expr-3
            {_n} = expr-1
            stop loop

        return {_r::*}
Errors:
Code:
[08:15:28 INFO]: [Skript] Reloading SortedList.sk...
[08:15:28 ERROR]: The return statement can only be used in a function (SortedList.sk, line 18: return Variables.getVariable({_name}, expr-2, expr-1.isLocal())')
[08:15:28 ERROR]: Can't understand this condition/effect: {_list}.sort(Entry.comparingByValue()) (SortedList.sk, line 26: {_list}.sort(Entry.comparingByValue())')
[08:15:28 INFO]: [Skript] Encountered 2 errors while reloading SortedList.sk!

Skript version: 2.4alpha4
Server version: paper 1.14.4
Skript addons: sk-yaml and sk-mirror.

Copied from: https://github.com/SkriptLang/Skript/issues/1743

Who can fix this error?

I only added these:
Code:
import:
    java.util.ArrayList
    java.util.Collections
You still need to import Entry (java.util.Map$Entry) and Variables (ch.njol.skript.variables.Variables)
 
Status
Not open for further replies.