Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » deleting clones
- lokarz368
-
Scratcher
27 posts
deleting clones
Here I'm making a snake game where the longer you are the more clones are in your tail but when the length gets to 17 or higher all the clones randomly disappear.The weird thing is, the snake keeps moving but is not creating any more clones despite the blocks on top of each other in the same forever loop. The clones are set to delete a few seconds after but that isn't the reason as i have a clone counter but it never changes. It would still change if the clones were being made and immediately deleted but it doesn't change. How do i fix?
Last edited by lokarz368 (Nov. 25, 2017 03:03:27)
- SpaceDragon1
-
New Scratcher
100+ posts
deleting clones
Can you link the project so we can see the project?
Thanks.
Thanks.
- mstone326
-
Scratcher
1000+ posts
deleting clones
Post the link here please. You have a few projects shared, none of which are named snake. Which project do you need help with?
- lokarz368
-
Scratcher
27 posts
deleting clones
I don't know whats wrong because the link takes me straight to the project page
- mstone326
-
Scratcher
1000+ posts
deleting clones
Looking quickly, your clones don't know who they are. You'll need to use a cloneID (for this sprite only) so the clones know who to delete and when. Also, you are making clones before getting the red.It is just always making clones. I'd think you'd only make a clone when you get a red piece.
look at this remix to see. So you're over the clone limit. Once the clone counter hits 300 (Scratch limit) then everything falls apart
https://scratch.mit.edu/projects/188645078/
look at this remix to see. So you're over the clone limit. Once the clone counter hits 300 (Scratch limit) then everything falls apart
https://scratch.mit.edu/projects/188645078/
- lokarz368
-
Scratcher
27 posts
deleting clones
The way it is set up is the clones don't move and after a while they delete so there always needs to be clones. But how would i do it for your way? I delete the clones so why would it get to the max?
Last edited by lokarz368 (Nov. 25, 2017 04:08:27)
- mstone326
-
Scratcher
1000+ posts
deleting clones
Here is tutorial by Deck26 about snake. See if it helps. And can be adapted to use clones instead of stamping but his methods are really well thought out. Give it a read. Hope it helps.
You delete the clones only when your condition is met exactly when a clone is created, so really if c > length + 1 when that exact clone is created, it is deleted. However, you are still creating 30 clones every second. So that script doesn't work because you can cruise around without getting any red peices, thus keeping c > length + 1 false, none get deleted, and boom, 300 clones in 10 seconds. All out
https://scratch.mit.edu/projects/42045208/#editor
You delete the clones only when your condition is met exactly when a clone is created, so really if c > length + 1 when that exact clone is created, it is deleted. However, you are still creating 30 clones every second. So that script doesn't work because you can cruise around without getting any red peices, thus keeping c > length + 1 false, none get deleted, and boom, 300 clones in 10 seconds. All out
https://scratch.mit.edu/projects/42045208/#editor
Last edited by mstone326 (Nov. 25, 2017 04:25:30)
- lokarz368
-
Scratcher
27 posts
deleting clones
No i didn't really understand it and it didn't explain all the data and stuff involved
- mstone326
-
Scratcher
1000+ posts
deleting clones
This is very very rough but it is getting late here but didn't want to leave y ou hanging. And typically Snake games work on a grid. But the idea is there to just create a clone when you need it and tell it to follow the list. Certainly don't need thousands of numbers in the list but once again, it is late so the idea is there. Hope it helps.
https://scratch.mit.edu/projects/188649211
Edit: the sprite's costume wasn't centered properly which caused the snakes to not line up properly. Now they do. The snake square is 14x14 pixels so I had the move block set to 15 to leave a pixel gap so you can see where the clones are.
https://scratch.mit.edu/projects/188649211
Edit: the sprite's costume wasn't centered properly which caused the snakes to not line up properly. Now they do. The snake square is 14x14 pixels so I had the move block set to 15 to leave a pixel gap so you can see where the clones are.
Last edited by mstone326 (Nov. 25, 2017 05:27:10)
- lokarz368
-
Scratcher
27 posts
deleting clones
Ok I've copied pretty much exactly what you have but only one clone spawns or all the clones are in the one spot. Like I said I made sure the scripts were all exactly the same so idk whats going on.
- mstone326
-
Scratcher
1000+ posts
deleting clones
Is your cloneID for this sprite only? A variable for this sprite only allows each clone to get its own copy of the variable. If not they will all respond to the one single variable. Looking at the code, they will go to their personal copy of cloneID which allows them to individually go to their item of the list
Last edited by mstone326 (Nov. 25, 2017 13:39:23)
- Discussion Forums
- » Help with Scripts
-
» deleting clones