Solved Issue deleting an element off a list, tuske GUI

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

Wynnevir

Well-Known Member
Jul 9, 2017
1,015
62
48
30
Elsewhere
Version: Bensku 2.2 dev 31c
Mc: 1.12.2
e7a9403f0f.png

Issue:
This may be a bit hard to explain, but I'll try and be thorough. The GUI I'm working with is supposed to delete the clicked home-set with shift-right-click: that portion works. However, it does not delete the correct home. It deletes the very first home on the list every time.
The whole list is represented by {homes::%{_p}%::%{_i}%}, where the index({_i}) is the chosen name for the home-set and the value is the coordinate location of the home. {_p} is the player name.
I have a test message that runs just before the removal that sends the value of {_i} and {homes::%{_p}%::%{_i}%} as a whole. It will send me the proper home-name and coordinates that I clicked on every time I click it.
But it will not delete that home, despite the value.

  • The home I click: test4
  • Test message sent: "test4 / x:#, y:#, z#"
  • What actually gets deleted: test1

It should be removing {homes::Wynnevir::test4}
not {homes::Wynnevir::test1}

It's recognizing that {_i} is test4 just before it doesn't use that value for {_i}. It's maddening. What am I doing wrong/missing?

code_language.skript:
if gui-click-action is right mouse button with shift:
    send "%{_i}% / %{homes::%{_p}%::%{_i}%}%" to {_p}
    remove {homes::%{_p}%::%{_i}%} from {homes::%{_p}%::*}
    wait 3 ticks
    homeList({_p}, 0)
code_language.skript:
function homeMsg(p: player, t: text):
    set {homes::%{_p}%::%{_t}%} to location of {_p}
    send "&e&l[&b&l✔&e&l] &r&7Home &l%{_t}% &7 set to %{homes::%{_p}%::%{_t}%}%" to {_p}
#--------------------------------
function sizeMsg(p: player):
    send "&e&l[&d&l✖&e&l] &r&7Home limit reached. Delete a home to set a new one" to {_p}
    stop   
#--------------------------------
function setHome(p: player, t: text):       
    loop {homes::%{_p}%::*}:
        if loop-index = {_t}:
            send "home name already exists." to {_p}
            stop
    if {_p} has permission "unlim.homes":
        homeMsg({_p}, {_t})
    else if {_p} has permission "10.homes":
        if size of {homes::%{_p}%::*} = 10:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
    else if {_p} has permission "5.homes":
        if size of {homes::%{_p}%::*} = 5:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
    else if {_p} has permission "4.homes":
        if size of {homes::%{_p}%::*} = 4:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
    else if {_p} has permission "3.homes":
        if size of {homes::%{_p}%::*} = 3:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
    else if {_p} has permission "1.homes":
        if size of {homes::%{_p}%::*} = 1:
            sizeMsg({_p})
        homeMsg({_p}, {_t})
        
function homeList(p: player, page: number):
    set {_liststart} to 9*{_page}
    set {_n} to 1
    set {_a} to 0
    set {_f} to 0
    wait 3 ticks
    create gui with virtual chest with 2 rows named "&9%{_p}%'s Homes":
        loop {homes::%{_p}%::*}:
            set {_v} to loop-value
            set {_i} to loop-index
            add 1 to {_f}
            if {_f} > {_liststart}:
                make gui slot {_a} with bed_item:3 named "%{_i}%" with lore "%{_v}%||&9left-click to TP||&9Shift+Right click to delete":
                    if gui-click-action is left mouse button:
                        teleport {_p} to {_v}
                    if gui-click-action is right mouse button with shift:
                        send "%{_i}% / %{homes::%{_p}%::%{_i}%}%" to {_p}
                        remove {homes::%{_p}%::%{_i}%} from {homes::%{_p}%::*}
                        wait 3 ticks
                        homeList({_p}, 0)
                add 1 to {_a}
                if {_a} = ((9*{_n})):
                    exit loop
        if size of {homes::%{_p}%::*} > {liststart} + 9:
            make gui slot 17 with emerald named "&dNext Page":
                homeList({_p}, ({_page} + 1))
        if {_page} > 0:
            make gui slot 9 with emerald named "&dPrevious Page":
                homeList({_p}, ({_page} - 1))
        open last gui to {_p}
    
command /delhome <text>:
    trigger:
        send "removed %{homes::%player%::%arg 1%}%"
        remove {homes::%player%::%arg 1%} from {homes::%player%::*}
        
command /home:
    aliases: /homes
    trigger:
        homeList(player, 0)
        
command /sethome <text>:
    trigger:
        set {_t} to arg 1
        setHome(player, {_t})
 
I don't know if this works but I've always had trouble with removing stuff from lists without looping them.

Try this:

loop {homes::%{_p}%::*}:
if loop-index-2 is {_i}:
remove loop-value-2 from {homes::%{_p}%::*}

Idk if that's the exact format but its something along those lines. Give it a shot, if it doesn't work then screw me.

It really all depends on what they are both stored in. If they are both texts then try: if "%loop-index-2%" is "%{_i}%":
 
Last edited:
Status
Not open for further replies.