Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Delete (Number) Of List
- Evan2963
- Scratcher
100+ posts
Delete (Number) Of List
Is there an easy way to delete say the first 654 items in a list? I tried
set [i v] to [1]
repeat until <[i] = [654]>
delete (i v) of [list]
change [i v] by (1)
end
Last edited by Evan2963 (Aug. 3, 2017 20:55:38)
Scratch Wiki editor and game designer!
Please check out some of my latest games and animations, or check out my website!
- TheCookieHero880
- Scratcher
100+ posts
Delete (Number) Of List
Is there an easy way to delete say the first 654 items in a list? I triedset [i v] to [1]
repeat until <[i] = [654]>
delete (i v) of [list]
change [i v] by (1)
end
What's the problem with your current script?
“Life is really simple, but we insist on making it complicated.” -Confucius
Check out The World's Hardest Platformer.
- Evan2963
- Scratcher
100+ posts
Delete (Number) Of List
It deletes every other item in the list insteadIs there an easy way to delete say the first 654 items in a list? I triedset [i v] to [1]
repeat until <[i] = [654]>
delete (i v) of [list]
change [i v] by (1)
end
What's the problem with your current script?
Scratch Wiki editor and game designer!
Please check out some of my latest games and animations, or check out my website!
- TheCookieHero880
- Scratcher
100+ posts
Delete (Number) Of List
set [i v] to [1]
repeat until <[i] = [654]>
delete (1 v) of [list]
change [i v] by (1)
end
“Life is really simple, but we insist on making it complicated.” -Confucius
Check out The World's Hardest Platformer.
- Ayarkay
- Scratcher
73 posts
Delete (Number) Of List
Let's say you run the above script on the following list:
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
So we set i = 1, and we delete item number i
So we delete item number 1, and our list now becomes:
{2, 3, 4, 5, 6, 7, 8, 9, 10}
Note that in this new list, the first element is 2, the second element is 3, the third element is 4, etc…
Now we increase i by 1, so i = 2.
So again, we delete item number i from the list, so we delete the second item in the list, and our list now becomes:
{2, 4, 5, 6, 7, 8, 9, 10}
Now increase i by 1, so i=3
Delete the ith element from the list, so delete the third element from the list:
{2, 4, 6, 7, 8, 9, 10}
Now i=4, so we delete the 4th item in the list:
{2, 4, 6, 8, 9, 10}
Finally i=5, so we delete the 5th element from the list:
{2, 4, 6, 8, 10}
Every time you delete an element from a list, all elements after it get moved up by 1 position in the list.
If you wanted to delete the first 654 elements from the list, you'd just do:
That way you don't need to continuously add 1 to your counter and to check if your counter = 654
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
So we set i = 1, and we delete item number i
So we delete item number 1, and our list now becomes:
{2, 3, 4, 5, 6, 7, 8, 9, 10}
Note that in this new list, the first element is 2, the second element is 3, the third element is 4, etc…
Now we increase i by 1, so i = 2.
So again, we delete item number i from the list, so we delete the second item in the list, and our list now becomes:
{2, 4, 5, 6, 7, 8, 9, 10}
Now increase i by 1, so i=3
Delete the ith element from the list, so delete the third element from the list:
{2, 4, 6, 7, 8, 9, 10}
Now i=4, so we delete the 4th item in the list:
{2, 4, 6, 8, 9, 10}
Finally i=5, so we delete the 5th element from the list:
{2, 4, 6, 8, 10}
Every time you delete an element from a list, all elements after it get moved up by 1 position in the list.
If you wanted to delete the first 654 elements from the list, you'd just do:
repeat (654)
delete (1 v) of [list v]
end
That way you don't need to continuously add 1 to your counter and to check if your counter = 654
Last edited by Ayarkay (Aug. 3, 2017 21:12:05)
- Evan2963
- Scratcher
100+ posts
Delete (Number) Of List
Thanks! It worked!set [i v] to [1]
repeat until <[i] = [654]>
delete (1 v) of [list]
change [i v] by (1)
end
Scratch Wiki editor and game designer!
Please check out some of my latest games and animations, or check out my website!
- TheCookieHero880
- Scratcher
100+ posts
Delete (Number) Of List
Let's say you run the above script on the following list:
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
So we set i = 1, and we delete item number i
So we delete item number 1, and our list now becomes:
{2, 3, 4, 5, 6, 7, 8, 9, 10}
Note that in this new list, the first element is 2, the second element is 3, the third element is 4, etc…
Now we increase i by 1, so i = 2.
So again, we delete item number i from the list, so we delete the second item in the list, and our list now becomes:
{2, 4, 5, 6, 7, 8, 9, 10}
Now increase i by 1, so i=3
Delete the ith element from the list, so delete the third element from the list:
{2, 4, 6, 7, 8, 9, 10}
Now i=4, so we delete the 4th item in the list:
{2, 4, 6, 8, 9, 10}
Finally i=5, so we delete the 5th element from the list:
{2, 4, 6, 8, 10}
Every time you delete an element from a list, all elements after it get moved up by 1 position in the list.
If you wanted to delete the first 654 elements from the list, you'd just do:repeat (654)
delete (1 v) of [list v]
end
That way you don't need to continuously add 1 to your counter and to check if your counter = 654
Correct. I was looking for the “repeat ( ) times” block, but for some reason I couldn't find it in the Scratchblocks menu
“Life is really simple, but we insist on making it complicated.” -Confucius
Check out The World's Hardest Platformer.
- Destroyer1727
- Scratcher
500+ posts
Delete (Number) Of List
it doesnt need to have the i variable just get a repeat block that repeates the deleting process 654 timesrepeat (654)
delete (1 v) of [list v]
end
for more information comment on my profile
Last edited by Destroyer1727 (Aug. 8, 2017 18:38:14)
I am the proud owner of ⭐Destroyer's Script Shop⭐
Please check out my account, Destroyer1727 and look at all my super fun games!
I love to help new scratchers so also check out my studio and project that are meant for just that!
I am also part of the VIS Collaboration! Please join it.
I am the owner of Coaches of Code with LilyPuplover.
I am the 18775968th user on scratch.
I used to work at Scratch Request Shop!
- Discussion Forums
- » Help with Scripts
- » Delete (Number) Of List