Discuss Scratch

Persimonai
Scratcher
9 posts

Advanced cloning

Hello everyone!

I'm trying to make a game snake with usage of cloning. So at the beginning of the game I have a snake that is a size of four small squares (one original sprite and three clones). Every time snake touches an apple a clone of the square is made and so my snake gets bigger.

In order to control my clones I've made three lists, one for x position, one for y position and one for direction. My script is shown bellow. The problem is that the clones doesn't know their number and because of that only first and last items of each list actually shows the x, y and direction of head and the 4th clone. How do I make all the members of the lists show x, y and direction of each clone?

when green flag clicked
delete ( all) of [list x]
delete ( all) of [list y]
delete ( all) of [list direction]
set [ no of square] to [1]
go to x: (0) y: (0)
point in direction ( 0)
add [] to [list x]
add [] to [list y]
add [] to [list direction]
repeat (3)
add [] to [list x]
add [] to [list y]
add [] to [list direction]
change [ no of square] by (1)
create clone of [ myself]
end
forever
move (2) steps
replace item ( 1) of [list x] with (x position)
replace item ( 1) of [list y] with (y position)
replace item ( 1) of [list direction] with (direction)
end



when I start as a clone
set [ myID] to (no of square)
forever
replace item ( myID) of [list x] with (x position)
replace item ( myID) of [list y] with (y position)
replace item ( myID) of [list direction] with (direction)
move (2) steps
end
Persimonai
Scratcher
9 posts

Advanced cloning

By the way, I did exactly as said in https://wiki.scratch.mit.edu/wiki/Advanced_Clone_Usage
If you look in the last section of the link called Scripting, it tells you to do exactly as I've done in my script. however unsuccessfully. Any ideas?
deck26
Scratcher
1000+ posts

Advanced cloning

I assume myID is a local (this sprite only) variable?

Share what you have and it will be easier to help.
Persimonai
Scratcher
9 posts

Advanced cloning

Thank you so much!
That was the mistake, I changed myID ‘For this sprite only’ and it worked! )

If you have couple of minutes, could you explain why does it make so much difference whether myID is visible for all sprites or this only?
asivi
Scratcher
1000+ posts

Advanced cloning

I know is too late because fortunately @deck26 has lead you to solve the issue, but anyway i'm going to give you a link showing a different aproach for that you want to do.
Caterpillar growing
deck26
Scratcher
1000+ posts

Advanced cloning

Persimonai wrote:

Thank you so much!
That was the mistake, I changed myID ‘For this sprite only’ and it worked! )

If you have couple of minutes, could you explain why does it make so much difference whether myID is visible for all sprites or this only?
If it's a local variable each clone has its own copy so can have different values for that variable and update different items in the list. In your scripts the sprite was updating item 1 in each list and the clones were all trying to update the same item as each other since myID just had the last value it was set to - so all clones saw myID as 4 and that's why only 1 and 4 were updating.
Scratch_Mapping
Scratcher
100+ posts

Advanced cloning

Maybe this will help
when green flag clicked
set [button number v] to [0]
repeat (3)
change [cutton number v] by (1)
create clone of [myself v]

end

 :: obsolete
:: #FFFFFF
:: pen
nalcwap
New to Scratch
7 posts

Advanced cloning

Scratch_Mapping wrote:

Maybe this will help
when green flag clicked
set [button number v] to [0]
repeat (3)
change [cutton number v] by (1)
create clone of [myself v]

end
i think you mean button not cutton rsrs
Persimonai
Scratcher
9 posts

Advanced cloning

Thank you all )

I finnished it Here's what I got

https://scratch.mit.edu/projects/130594006/
asivi
Scratcher
1000+ posts

Advanced cloning

Persimonai wrote:

Thank you all )

I finnished it Here's what I got

https://scratch.mit.edu/projects/130594006/
It works fine!

Powered by DjangoBB