1. 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!


    You can always check our our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Issue deleting an element off a list, tuske GUI

Discussion in 'Skript' started by Wynnevir, Jan 3, 2018.

Thread Status:
Not open for further replies.
  1. Wynnevir

    Wynnevir Well-Known Member

    Jul 9, 2017
    Likes Received:
    Version: Bensku 2.2 dev 31c
    Mc: 1.12.2

    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 (Skript):
    1. if gui-click-action is right mouse button with shift:
    2.     send "%{_i}% / %{homes::%{_p}%::%{_i}%}%" to {_p}
    3.     remove {homes::%{_p}%::%{_i}%} from {homes::%{_p}%::*}
    4.     wait 3 ticks
    5.     homeList({_p}, 0)
    Code (Skript):
    1. function homeMsg(p: player, t: text):
    2.     set {homes::%{_p}%::%{_t}%} to location of {_p}
    3.     send "&e&l[&b&l✔&e&l] &r&7Home &l%{_t}% &7 set to %{homes::%{_p}%::%{_t}%}%" to {_p}
    4. #--------------------------------
    5. function sizeMsg(p: player):
    6.     send "&e&l[&d&l✖&e&l] &r&7Home limit reached. Delete a home to set a new one" to {_p}
    7.     stop  
    8. #--------------------------------
    9. function setHome(p: player, t: text):      
    10.     loop {homes::%{_p}%::*}:
    11.         if loop-index = {_t}:
    12.             send "home name already exists." to {_p}
    13.             stop
    14.     if {_p} has permission "unlim.homes":
    15.         homeMsg({_p}, {_t})
    16.     else if {_p} has permission "10.homes":
    17.         if size of {homes::%{_p}%::*} = 10:
    18.             sizeMsg({_p})
    19.         homeMsg({_p}, {_t})
    20.     else if {_p} has permission "5.homes":
    21.         if size of {homes::%{_p}%::*} = 5:
    22.             sizeMsg({_p})
    23.         homeMsg({_p}, {_t})
    24.     else if {_p} has permission "4.homes":
    25.         if size of {homes::%{_p}%::*} = 4:
    26.             sizeMsg({_p})
    27.         homeMsg({_p}, {_t})
    28.     else if {_p} has permission "3.homes":
    29.         if size of {homes::%{_p}%::*} = 3:
    30.             sizeMsg({_p})
    31.         homeMsg({_p}, {_t})
    32.     else if {_p} has permission "1.homes":
    33.         if size of {homes::%{_p}%::*} = 1:
    34.             sizeMsg({_p})
    35.         homeMsg({_p}, {_t})
    37. function homeList(p: player, page: number):
    38.     set {_liststart} to 9*{_page}
    39.     set {_n} to 1
    40.     set {_a} to 0
    41.     set {_f} to 0
    42.     wait 3 ticks
    43.     create gui with virtual chest with 2 rows named "&9%{_p}%'s Homes":
    44.         loop {homes::%{_p}%::*}:
    45.             set {_v} to loop-value
    46.             set {_i} to loop-index
    47.             add 1 to {_f}
    48.             if {_f} > {_liststart}:
    49.                 make gui slot {_a} with bed_item:3 named "%{_i}%" with lore "%{_v}%||&9left-click to TP||&9Shift+Right click to delete":
    50.                     if gui-click-action is left mouse button:
    51.                         teleport {_p} to {_v}
    52.                     if gui-click-action is right mouse button with shift:
    53.                         send "%{_i}% / %{homes::%{_p}%::%{_i}%}%" to {_p}
    54.                         remove {homes::%{_p}%::%{_i}%} from {homes::%{_p}%::*}
    55.                         wait 3 ticks
    56.                         homeList({_p}, 0)
    57.                 add 1 to {_a}
    58.                 if {_a} = ((9*{_n})):
    59.                     exit loop
    60.         if size of {homes::%{_p}%::*} > {liststart} + 9:
    61.             make gui slot 17 with emerald named "&dNext Page":
    62.                 homeList({_p}, ({_page} + 1))
    63.         if {_page} > 0:
    64.             make gui slot 9 with emerald named "&dPrevious Page":
    65.                 homeList({_p}, ({_page} - 1))
    66.         open last gui to {_p}
    68. command /delhome <text>:
    69.     trigger:
    70.         send "removed %{homes::%player%::%arg 1%}%"
    71.         remove {homes::%player%::%arg 1%} from {homes::%player%::*}
    73. command /home:
    74.     aliases: /homes
    75.     trigger:
    76.         homeList(player, 0)
    78. command /sethome <text>:
    79.     trigger:
    80.         set {_t} to arg 1
    81.         setHome(player, {_t})

  2. Best Answer:
    Post #3 by Pikachu, Jan 4, 2018
  3. Revelationage

    Revelationage Well-Known Member

    Jan 27, 2017
    Likes Received:
    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}%":
    #2 Revelationage, Jan 3, 2018
    Last edited: Jan 3, 2018
  4. Pikachu

    Moderator Supporter Addon Developer

    Jan 25, 2017
    Likes Received:
    Don't use remove just delete it directly
  5. Wynnevir

    Wynnevir Well-Known Member

    Jul 9, 2017
    Likes Received:
    OH how simple D:. Is there a reason removing it from the list wasn't working?
    And thank you!
  6. Pikachu

    Moderator Supporter Addon Developer

    Jan 25, 2017
    Likes Received:
    Removing deletes the first match from the list where as delete deletes that specific thing
    • Informative Informative x 1
Thread Status:
Not open for further replies.