Discuss Scratch

Deseptor
Scratcher
26 posts

one clone only spawns every other restart

This code makes 15 clones and changes costume to make a level select screen. It works perfectly, except for the fact that level 1 only appears every other time running the program. (e.g. run the program and it'll show, run it again and it won't, run it again and it will). All other levels appear fine every time. How could I fix this?

when green flag clicked
go to [front v] layer :: looks
set [clones v] to (0)
set [iterator 1 v] to (0)
switch costume to [home1 v]

when I receive [Screen change v]
set [clones v] to (0)
set [iterator 1 v] to (0)
switch costume to [home1 v]
hide
broadcast [delete levelbuttons v]
if <(World: current level) = [Level Menu 1]> then {
switch costume to [home1 v]
show
repeat (length of [Page 1 level button positions v] :: list) {
change [iterator 1 v] by (1)
create clone of [myself v]
change [clones v] by (1)
} :: control
} else {
hide
} :: control

when I start as a clone
go to [front v] layer :: looks
if <not <(World: current level) = [Level Menu 1]>> then {
stop [this script v]
} :: control
set [coordinate in progress v] to [x]
set [iterator 2 v] to (0)
set [x v] to []
set [y v] to []
switch costume to (join [level] (iterator 1))
repeat (length of (item (iterator 1) of [Page 1 level button positions v] :: list)) {
change [iterator 2 v] by (1)
if <(letter (iterator 2) of (item (iterator 1) of [Page 1 level button positions v] :: list)) = []> then {
set [coordinate in progress v] to [y]
} else {
if <(coordinate in progress) = [x]> then {
set [x v] to (join (x) (letter (iterator 2) of (item (iterator 1) of [Page 1 level button positions v] :: list)))
} else {
set [y v] to (join (y) (letter (iterator 2) of (item (iterator 1) of [Page 1 level button positions v] :: list)))
} :: control
} :: control
} :: control
go to x: (x) y: (y)
forever {
if <<mouse down?> and <touching [mouse pointer v]?>> then {
if <(costume [name v] :: looks) = [home1]> then {
if <(home1: unlocked?) = [false]> then {
say that level [home1] is locked :: custom
} else {
broadcast [delete levelbuttons v]
warp to level [home1] :: custom
} :: control
} :: control
if <(costume [name v] :: looks) = [level1]> then {
if <(level1: unlocked?) = [false]> then {
say that level [level1] is locked :: custom
} else {
broadcast [delete levelbuttons v]
warp to level [level1] :: custom
} :: control
} :: control
if <(costume [name v] :: looks) = [level2]> then {
if <(level2: unlocked?) = [false]> then {
say that level [level2] is locked :: custom
} else {
broadcast [delete levelbuttons v]
warp to level [level2] :: custom
} :: control
} :: control
} :: control
} :: control cap

when I receive [delete levelbuttons v]
set [clones v] to (0)
delete this clone

define say that level (level) is locked
say (join (level) [ is currently locked! Beat the previous level to unlock it.]) for (5) secs

define warp to level (level)
if <(level) = [home1]> then {
set [Level: sections v] to (1)
} :: control
if <(level) = [level1]> then {
set [Level: sections v] to (8)
} :: control
if <(level) = [level2]> then {
set [Level: sections v] to (9)
} :: control
set [World: current level v] to (level)
set [Level: current section v] to (1)
broadcast [Screen change v]

Here's what the
(Page 1 level button positions :: list)
list looks like, if you're curious:

1. -75,105
2. 25,105
3. 125,105
4. -175,35
5. -75,35
6. 25,35
7. 125,35
8. -175,-35
9. -75,-35
10. 25,-35
11. 125,-35
12. -175,-105
13. -75,-105
14. 25,-105
15. 125,-105
SquakyDude
Scratcher
100+ posts

one clone only spawns every other restart

Try to limit when green flag clicked events and put them together


-@SquakyDude (:
deck26
Scratcher
1000+ posts

one clone only spawns every other restart

Share the project please. It's much easier to make sense of code if we can play around with it.

Powered by DjangoBB