Saving location to 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.

Red Tardis

Member
Dec 22, 2021
2
0
1
23
So i have this script, which starts an infinite loop when a player joins, where it adds current player's location to list every tick. When the list hits some size, it deletes the first saved location. That way list should have a fixed size and sort of like shift (as example: [1,2,3,4] -> [2,3,4,5] -> [3,4,5,6] ...]).
The point is to store last 3 seconds (60 ticks) of player's movement. But when I test it, the list of locations stays always the same as 3 seconds after player joined and doesn't update.
I tried different variations of this algorithm, but nothing seems to work. What am I doing wrong here?
Code:
on join:
    set {s%player%} to true
    while {s%player%} is true:
        add location of the player to {locs%player%::*}
        if size of {locs%player%::*} is 61:
            delete {locs%player%::1}
        wait 1 tick
 
So i have this script, which starts an infinite loop when a player joins, where it adds current player's location to list every tick. When the list hits some size, it deletes the first saved location. That way list should have a fixed size and sort of like shift (as example: [1,2,3,4] -> [2,3,4,5] -> [3,4,5,6] ...]).
The point is to store last 3 seconds (60 ticks) of player's movement. But when I test it, the list of locations stays always the same as 3 seconds after player joined and doesn't update.
I tried different variations of this algorithm, but nothing seems to work. What am I doing wrong here?
Code:
on join:
    set {s%player%} to true
    while {s%player%} is true:
        add location of the player to {locs%player%::*}
        if size of {locs%player%::*} is 61:
            delete {locs%player%::1}
        wait 1 tick
I'm not sure but maybe try this?

Code:
on join:
    set {s%player%} to true
    while {s%player%} is true:
        add location of the player to {locs%player%::*}
        if size of {locs%player%::*} is 61:
            remove {locs%player%::1} from {locs%player%::*}
        wait 1 tick
 
I'm not sure but maybe try this?

Code:
on join:
    set {s%player%} to true
    while {s%player%} is true:
        add location of the player to {locs%player%::*}
        if size of {locs%player%::*} is 61:
            remove {locs%player%::1} from {locs%player%::*}
        wait 1 tick

I tried this method. The problem is not in the deleting the element. I actually managed to find a solution. I just reassign the list after it hits the limit:
Code:
on join:
    set {s%player%} to true
    while {s%player%} is true:
        add location of the player to {locs%player%::*}
        if size of {locs%player%::*} is 61:
            remove {locs%player%::1} from {locs%player%::*}
            set {locs%player%::*} to {locs%player%::*}
        wait 1 tick

Not completely sure why it works, but it works :emoji_slight_smile:
 
Status
Not open for further replies.