Discuss Scratch

MsTirre
Scratcher
6 posts

Crazy Code Making my Brain Melt

A student and I have have been working together to create a little farm tycoon game. We are trying to create a watering bonus system that makes it so that for 30 seconds you do not have to water the plants. But it isn't responding as expected. Can someone take a peek before my brain explodes?

https://scratch.mit.edu/projects/1015724390
yadayadayadagoodbye
Scratcher
1000+ posts

Crazy Code Making my Brain Melt

Could you include some more details? I cannot seem to figure out how the project is supposed to function (The plants seem to live fine without water, and when I water them, they seem to die rather then live)

edit: after a bit of code tracing, I think I see what you are trying to do.

There are most definitly more eloquent solutions, but a simple solution would be to use the following code:

when I receive [water powerup v]
reset timer
repeat until <(timer) > [30]>
set [plant 1 warning v] to [n]
do this for any other plant warnings that you want to affect as well ::#808080
end
broadcast [plot 1 water v]
do this for all other plants whose warnings you affected ::#808080

Last edited by yadayadayadagoodbye (May 8, 2024 03:43:37)


Scratchers that I've cati-fied
MsTirre
Scratcher
6 posts

Crazy Code Making my Brain Melt

Oh my goodness, you are amazing. I didn't even think about using timer from sensing. If the water warning runs too long it is supposed to kill the plant. Still some work to clean it up and I am sure there are much better ways to make it do what we have going on.
RokCoder-TestAccount
Scratcher
27 posts

Crazy Code Making my Brain Melt

Although this isn't what you asked, I would strongly recommend looking into the use of clones. Right now you have 22 sprites of which 15 replicate code from other sprites (e.g. plot 1, 2, 3, 4, 5 and 6 are essentially the same). It wouldn't take a great deal of work to convert to using clones and you would then (a) have a more manageable project with only 7 sprites and (b) reduce the risk of bugs occurring when you need to make changes which means making changes to all the duplicates as well.

Last edited by RokCoder-TestAccount (May 9, 2024 10:03:22)



Scratch dabbling for fun…

MsTirre
Scratcher
6 posts

Crazy Code Making my Brain Melt

I wasn't sure how to make them react separately with their own water warning systems. Can you help me understand how I make the clones act separately?
qwertycodechamp90411
Scratcher
100+ posts

Crazy Code Making my Brain Melt

MsTirre wrote:

I wasn't sure how to make them react separately with their own water warning systems. Can you help me understand how I make the clones act separately?
Use clone ID's.

Make a variable (for this sprite only) and change it so that each clone will start with a different id. Then you can tell the clones apart.

when green flag clicked
set [id v] to (0)
repeat (6)
change [id v] by (1)
create clone of [myself v]

Useful Links: Text Generator ——— Encoders/Decoders (Normal, Case Sensitive) ——— New Math Blocks ——— Comment what next on my profile!
Wait, we’re at 900 million projects? So close to 1 billion projects uploaded to the server!

<((x) ^ ((1) / (y))::operators) = ((y) √ (x)::operators)> // is false if x < 0???
Hi! I'm qwertycodechamp90411. I'm most active on the suggestions forum and the help with scripts forum, because I like to help other people and improve scratch! I like to think I'm good at scratch, but there's a lot I don't know/understand (how on earth do scrolling platformers work lol). As a general rule of thumb, I should have the answer if it's math related, because I'm a very stereotypical nerd when it comes to math.
MsTirre
Scratcher
6 posts

Crazy Code Making my Brain Melt

Sorry for all the questions. Do I just use

if <<(id) = [1]>> then

To refer to the exact clone I am targeting?

Last edited by MsTirre (May 16, 2024 15:35:32)

_turtle64
Scratcher
100+ posts

Crazy Code Making my Brain Melt

MsTirre wrote:

Sorry for all the questions. Do I just use

if <<(id) = [1]>> then

To refer to the exact clone I am targeting?
Yes


Powered by DjangoBB