How to make a system that removes a specific index of list and move all indexes after that down 1 step?

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

DankThanos

Member
Feb 5, 2024
1
0
1
23
I am making a /changelog command and I am trying to make a remove system, by running the command /changelog remove 2 it should remove the 2nd row of the changelog and move the rows beneath it up one step. Although, the last row doesn't seem to correctly change position.

if i would have the changelog:

Changelog:
- change1
- change2
- change3
- change4

and do /changelog remove 2,
it should be:


Changelog
- change1
- change3
- change4

but instead, it becomes:

Changelog
- change1
- change3
- <none>
- change4

Code:
command /changelog [<string>] [<string>] [<string>]:
    executable by: players and console
    trigger:

    # other code

        else if arg 1 is "remove" or "delete" or "del":
            if player has permission "op":
                set {_changeIndex} to arg 2 parsed as integer
                set {_index} to size of {changelog::*}
                delete {changelog::%{_changeIndex}%}
                send "&aSuccessfully removed &echange %arg 2%" to event-player
                set {_changelogSize} to size of {changelog::*}
                set {_loopCount} to 0
                loop {_changelogSize} - {_changeIndex} + 1 times:
                    set {changelog::%{_changeIndex} + {_loopCount}%} to {changelog::%{_changeIndex} + {_loopCount} + 1%}
                    add 1 to {_loopCount}
                send {_changelogSize} to event-player
                send {changelog::%{_changelogSize}%} to event-player
                delete {changelog::%{_changelogSize}%}
 
Hey! So what I think is wrong with your code: If you use add to add the changelogs it will start with 1
So it will set {changelog::0} which is not defined to {changelog::1} which is now overwritten to <none> it will continue that to the end so your last value will be <none> and should be all blank. I dont think I understand the whole issue yet as I cant really review a code that gives me vars when I cant see when/how it sets them.

I think if you replace this:
Code:
set {_loopCount} to 0
loop {_changelogSize} - {_changeIndex} + 1 times:
    set {changelog::%{_changeIndex} + {_loopCount}%} to {changelog::%{_changeIndex} + {_loopCount} + 1%}
    add 1 to {_loopCount}
    
(This is the broken code)

With the fix:
Code:
loop {changelog::*}:
    add {changelog::%loop-index%} to {changelogtemp::*}
clear {changelog::*}
set {changelogtemp::*} to {changelog::*}

It should work