Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to create a color detector?
- fresandia10
- Scratcher
21 posts
How to create a color detector?
I've created a game (currently unshared since this is a major update) and I'm trying to make the main sprite detect a certain color and show it there.
The backdrop is light brown framed by dark brown. The sprite (usually a blue square, but changes with the holidays, i.e. it's a red envelope on Lunar New Year.) The blue square will find a random spot on the screen, and if it's on the dark brown, it'll find another spot. This will keep on going until the spot is light brown.
So far, I've tried this:
which doesn't work…it keeps on showing up in the same position every time! (And in the darker brown!)
This will happen a lot. When the game starts, the blue square will appear randomly after 2-11 seconds. You get a point if you press it before the timer goes off. (If you don't accomplish this, you lose points. You won't die, but having -234 points is worse than dying, right?)
Afterwards, the square will disappear, whether you successfully pressed it in time or not. It'll do the 2-11 second cooldown again, but this time in a different spot. I want this to always appear in the light brown.
I've got everything figured out except for the spawning thing. Can y'all help me, please?
The backdrop is light brown framed by dark brown. The sprite (usually a blue square, but changes with the holidays, i.e. it's a red envelope on Lunar New Year.) The blue square will find a random spot on the screen, and if it's on the dark brown, it'll find another spot. This will keep on going until the spot is light brown.
So far, I've tried this:
when green flag clicked
hide
when I receive [actually start v]
repeat until <touching color [#ffbf00]?>
go to [ random position v]
if <touching color [#806000] ?> then
go to [ random position v]
end
end
show
which doesn't work…it keeps on showing up in the same position every time! (And in the darker brown!)
This will happen a lot. When the game starts, the blue square will appear randomly after 2-11 seconds. You get a point if you press it before the timer goes off. (If you don't accomplish this, you lose points. You won't die, but having -234 points is worse than dying, right?)
Afterwards, the square will disappear, whether you successfully pressed it in time or not. It'll do the 2-11 second cooldown again, but this time in a different spot. I want this to always appear in the light brown.
I've got everything figured out except for the spawning thing. Can y'all help me, please?
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- BetaBuilds
- Scratcher
12 posts
How to create a color detector?
Try this
when I receive [actually start]
repeat until <<not <touching color [dark brown/border color] ?>> and <touching color [lightbrown] ?>>
go to [random position]
end
show
Last edited by BetaBuilds (April 1, 2024 23:13:29)
- fresandia10
- Scratcher
21 posts
How to create a color detector?
That did help it get out of the dark brown, but it keeps on spawning in the same point every time!
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- BetaBuilds
- Scratcher
12 posts
How to create a color detector?
Try putting a go to random position before the repeat-until.
- fresandia10
- Scratcher
21 posts
How to create a color detector?
Try thiswhen I receive [actually start]
repeat until <<not <touching color [dark brown/border color] ?>> and <touching color [lightbrown] ?>>
go to [random position]
end
show
Unfortunately, that didn't work! The blue square keeps on spawning in the same spot. It's light brown, but I'd like it to go somewhere else.
Edit: Woah, I'm not sure what I did, but I fixed it!
Edit: nope, i lied. it unfixed. This time it's stuck at a new spot.
Last edited by fresandia10 (April 1, 2024 23:32:18)
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- SpyCoderX
- Scratcher
1000+ posts
How to create a color detector?
Could you share the project?
^ Below this line is my signature ^
New to the forums? Click here!
<Skilled Coder | Forum Helper (about) | Scratch Lab>
What we need may not be what we want.
Banner by Scratchboxes
- han614698
- Scratcher
1000+ posts
How to create a color detector?
There might be only one location on the stage that doesn't touch dark brown and the sprite fits.
<Scratch Wikian // 2000+ Edits | Forum Helper // 7000+ Posts | Scratcher // 530+ Followers>
banner coming soon…
- fresandia10
- Scratcher
21 posts
How to create a color detector?
There might be only one location on the stage that doesn't touch dark brown and the sprite fits.
The sprite is quite small, and the frame isn't that large. The spirte does a good job of spawning in light brown areas, but I just want it to appear in a different light brown area each time.
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- SpyCoderX
- Scratcher
1000+ posts
How to create a color detector?
Hmm. This is more difficult. You could try something like this:There might be only one location on the stage that doesn't touch dark brown and the sprite fits.
The sprite is quite small, and the frame isn't that large. The spirte does a good job of spawning in light brown areas, but I just want it to appear in a different light brown area each time.
(areas ::list) //areas
define add areas (x) (y) (size)
add (x) to [areas v]
add (y) to [areas v]
add (size) to [areas v]
define random go to
//run without screen refresh
set [area v] to (pick random (1) to ((length of [areas v])/(3))
set [x v] to (item (area) of [areas v])
set [y v] to (item ((area)+(1)) of [areas v])
set [size v] to (item ((area)+(2)) of [areas v])
go to x: (pick random ((x)-(size ::variables)) to ((x)+(size ::variables))) y: (pick random ((y)-(size ::variables)) to ((y)+(size ::variables)))
repeat until <<touching color [good color] ?> and <not <touching color [bad color] ?>>>
go to x: (pick random ((x)-(size ::variables)) to ((x)+(size ::variables))) y: (pick random ((y)-(size ::variables)) to ((y)+(size ::variables)))
Hope this helps!
^ Below this line is my signature ^
New to the forums? Click here!
<Skilled Coder | Forum Helper (about) | Scratch Lab>
What we need may not be what we want.
Banner by Scratchboxes
- fresandia10
- Scratcher
21 posts
How to create a color detector?
Hmm. This is more difficult. You could try something like this:There might be only one location on the stage that doesn't touch dark brown and the sprite fits.
The sprite is quite small, and the frame isn't that large. The spirte does a good job of spawning in light brown areas, but I just want it to appear in a different light brown area each time.(areas ::list) //areas
define add areas (x) (y) (size)
add (x) to [areas v]
add (y) to [areas v]
add (size) to [areas v]
define random go to
//run without screen refresh
set [area v] to (pick random (1) to ((length of [areas v])/(3))
set [x v] to (item (area) of [areas v])
set [y v] to (item ((area)+(1)) of [areas v])
set [size v] to (item ((area)+(2)) of [areas v])
go to x: (pick random ((x)-(size ::variables)) to ((x)+(size ::variables))) y: (pick random ((y)-(size ::variables)) to ((y)+(size ::variables)))
repeat until <<touching color [good color] ?> and <not <touching color [bad color] ?>>>
go to x: (pick random ((x)-(size ::variables)) to ((x)+(size ::variables))) y: (pick random ((y)-(size ::variables)) to ((y)+(size ::variables)))
Hope this helps!
I think this broke it, now the sprite doesn't appear anymore
Last edited by fresandia10 (April 3, 2024 17:17:52)
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- SpyCoderX
- Scratcher
1000+ posts
How to create a color detector?
Can you share the project?-snip-
I think this broke it, now the sprite doesn't appear anymore
^ Below this line is my signature ^
New to the forums? Click here!
<Skilled Coder | Forum Helper (about) | Scratch Lab>
What we need may not be what we want.
Banner by Scratchboxes
- fresandia10
- Scratcher
21 posts
How to create a color detector?
Can you share the project?-snip-
I think this broke it, now the sprite doesn't appear anymore
Already done. It's called “Quick Click!” and I'm just looking for the spawn script.
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- SpyCoderTest
- Scratcher
56 posts
How to create a color detector?
It isn't showing up because you have a “hide” block the “when i receive start” forever loop.Can you share the project?-snip-
I think this broke it, now the sprite doesn't appear anymore
Already done. It's called “Quick Click!” and I'm just looking for the spawn script.
Have a good day/night!
This is SpyCoderX's alt
\(-_-) ::#00AAAA //This is crypto. He protects my signature from the evil kumquats!Programming is a very powerful skill. As are critical thinking and hard work.
- SpyCoderX
- fresandia10
- Scratcher
21 posts
How to create a color detector?
It isn't showing up because you have a “hide” block the “when i receive start” forever loop.Can you share the project?-snip-
I think this broke it, now the sprite doesn't appear anymore
Already done. It's called “Quick Click!” and I'm just looking for the spawn script.
But I put the show block, yeah? Why isn't it showing up then?
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- SpyCoderTest
- Scratcher
56 posts
How to create a color detector?
Because the hide block is after the show block it overrides the show block.-snip-
But I put the show block, yeah? Why isn't it showing up then?
Have a good day/night!
This is SpyCoderX's alt
\(-_-) ::#00AAAA //This is crypto. He protects my signature from the evil kumquats!Programming is a very powerful skill. As are critical thinking and hard work.
- SpyCoderX
- fresandia10
- Scratcher
21 posts
How to create a color detector?
Because the hide block is after the show block it overrides the show block.-snip-
But I put the show block, yeah? Why isn't it showing up then?
How does that work then? Should I do the forever loop in the message broadcast then?
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- Discussion Forums
- » Help with Scripts
- » How to create a color detector?