Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » clones clone if i press space
- atmi9985
-
Scratcher
17 posts
clones clone if i press space
the issue is simple when i press space it creates a clone but when i press few more i can t clone anymore so i added clone count variable so when i cloned until i can t clone the lone count said 294 clones witch i just pressed few times space how do i fix it
- deck26
-
Scratcher
1000+ posts
clones clone if i press space
Sounds like you have clones creating clones so they're multiplying faster than you realise. The limit is 300 clones but perhaps another sprite has a handful of clones which aren't in your count.
Use a local (this sprite only) variable to differentiate between the sprite and clones or get an uncloned sprite to create the clones of the one to be cloned.
Use a local (this sprite only) variable to differentiate between the sprite and clones or get an uncloned sprite to create the clones of the one to be cloned.
- StarWalker600
-
Scratcher
100+ posts
clones clone if i press space
the issue is simple when i press space it creates a clone but when i press few more i can t clone anymore so i added clone count variable so when i cloned until i can t clone the lone count said 294 clones witch i just pressed few times space how do i fix ityeah thats cuz scratch is a programming language running on computer, & computers are super fast. So if u press space js for like a second, for computer u pressed space for 1000ms. As scratch generally works on 30fps, that means pressing space for js 1 second will generate ~30 clones if it generates 1 clone/frame (i dont think it does but still). So to get around this add some delay to ur code. A delay of maybe 0.25 seconds or 0.5 seconds is usually enough. u can do this with the
wait () secsblock. so ur code should be smth like this:
when [Space v] key pressed // or u can use if & the key pressed block from sensing
create clone of [myself v]
wait (0.5) seconds // u can increase this beyond 1 seconds to make it spam proof
This is a very very very common error that beginners get. If u get any problem like this where you click smth & it happen multiple times, then adding delay to ur code is the best solution.
Last edited by StarWalker600 (Dec. 13, 2024 16:23:04)
- AHypnoman
-
Scratcher
1000+ posts
clones clone if i press space
If you don't want clones to clone, you'll have to have your program ‘remember’ that they're a clone.
Create a variable with the ‘for this sprite only’ toggle turned on. Name it something like this:
Then add this code to the original sprite so that it stores that it isn't a clone:
Then when a clone is created, give it this code so that it stores that it is a clone:
Then to create clones when space is pressed, use this code:
You were having this problem because the ‘when space key pressed’ block wasn't just running in the original sprite, but also in all of the clones, so they were all cloning themselves. I've fixed it by stopping clones from ever running the ‘create clone of this sprite’ block in the ‘when space key pressed’ block runs.
Create a variable with the ‘for this sprite only’ toggle turned on. Name it something like this:
(am I a clone?)
Then add this code to the original sprite so that it stores that it isn't a clone:
when green flag clicked
set [am I a clone? v] to [false]
Then when a clone is created, give it this code so that it stores that it is a clone:
when I start as a clone
set [am I a clone? v] to [true]
Then to create clones when space is pressed, use this code:
when [space v] key pressed
if <(am I a clone?) = [true]> then
create clone of [this sprite v]
end
You were having this problem because the ‘when space key pressed’ block wasn't just running in the original sprite, but also in all of the clones, so they were all cloning themselves. I've fixed it by stopping clones from ever running the ‘create clone of this sprite’ block in the ‘when space key pressed’ block runs.
- atmi9985
-
Scratcher
17 posts
clones clone if i press space
hey but when i tried am i clone thingy it was the same the issue is when i place the clone the clone who i placed is cloning in dublication way example when i plant clone nothing realy happens when i place 2 clone the cloen count switches to 3 and clone i placed is clone again when i place again clone it just clones more
- deck26
-
Scratcher
1000+ posts
clones clone if i press space
Share the project if you need help sowe can focus the help better.
- atmi9985
-
Scratcher
17 posts
clones clone if i press space
ok i copied the scripts into a project they work as intended i also added comments what stuff are dioing if you plant it 2 times please drag it because you might find issue im dealin with also planted variable is clone count
https://scratch.mit.edu/projects/1110770234/
https://scratch.mit.edu/projects/1110770234/
Last edited by atmi9985 (Dec. 14, 2024 18:23:35)
- AHypnoman
-
Scratcher
1000+ posts
clones clone if i press space
ok i copied the scripts into a project they work as intended i also added comments what stuff are dioing if you plant it 2 times please drag it because you might find issue im dealin with also planted variable is clone count
https://scratch.mit.edu/projects/1110770234/
this should work:
remove the 'if <(am i a clone?) = > then' block (keep what's in it though)
then create a new variable (name it something like ‘am i a clone? number 2’) - and this is really, really important, make sure you press the ‘For this sprite only’ button in the variable creation menu. This lets the clones distinguish themselves from one another
next, replace all of the old ‘(am i a clone?)’ variables with ‘(am i a clone? number 2)’ variables
if you want to, delete the old ‘(am i a clone?)’ variables and remove ‘number 2’ from the name of the new variable by renaming it (you don't have to do this, but it might make your code look cleaner)
then replace the 'when I receive ; create a clone of (myself v)' blocks with this code:
when I receive [test the plant v]
if <(am i a clone?) = [false]> then // make sure this says false
create clone of [myself v]
end
- atmi9985
-
Scratcher
17 posts
clones clone if i press space
i tried it can you try remixing project i wann realy peek at script you fixed and fixing issue i don t realy understand like i tried dioing that clone count and other help you tried all i tried the its just same
Last edited by atmi9985 (Dec. 15, 2024 12:28:40)
- AHypnoman
-
Scratcher
1000+ posts
clones clone if i press space
i tried it can you try remixing project i wann realy peek at script you fixed and fixing issue i don t realy understand like i tried dioing that clone count and other help you tried all i tried the its just sameI've remixed the project with my changes under an alt account (@wv-)
- GameCatastrophe0927
-
Scratcher
1000+ posts
clones clone if i press space
Clones react to all hat blocks, including broadcasts and key presses. :: hat :: eventsPeople have suggested variable solutions, which is helpful in some situations, but for the best optimization you can do this:
when @greenFlag clicked or broadcast :: hat :: events
forever
if <key (space v) pressed> then
create clone of [myself v]
wait until <not <key (space v) pressed>>
end
end
Last edited by GameCatastrophe0927 (Dec. 20, 2024 17:01:44)
- AHypnoman
-
Scratcher
1000+ posts
clones clone if i press space
Tmk this runs slower than how they were handling user input. Also this wouldn't solve the problem (if it were triggered by a broadcast as you suggest)Clones react to all hat blocks, including broadcasts and key presses. :: hat :: eventsPeople have suggested variable solutions, which is helpful in some situations, but for the best optimization you can do this:when @greenFlag clicked or broadcast :: hat :: events
forever
if <key (space v) pressed> then
create clone of [myself v]
wait until <not <key (space v) pressed>>
end
end
- michaeljackson1365
-
Scratcher
1000+ posts
clones clone if i press space
…As scratch generally works on 30fps, that means pressing space for js 1 second will generate ~30 clones if it generates 1 clone/frame (i dont think it does but still)…That's on the original sprite. If you take into account that the clones clone more clones, without the clone limit on Scratch, 30 clones/second (accounting that the clones clone themselves when running this script:
when [space v] key pressed9920 clones per second. However, the number of clones explodes exponentially because the clones make more clones, it would be squared every two seconds, and if you take that to three seconds, cubed. This would inevitably crash your computer, so that's one reason why there's a clone limit
create clone of [myself v]
Last edited by michaeljackson1365 (Dec. 20, 2024 17:35:32)
- atmi9985
-
Scratcher
17 posts
clones clone if i press space
i know how make clone limits i already know how do it
- Discussion Forums
- » Help with Scripts
-
» clones clone if i press space