Discuss Scratch

CrazyCreeper380
Scratcher
9 posts

How to add an ending script (check the message for more information)

Hi There.
I need help with my project, Virtual Pet
When my Energy bar is equal to 0, the sprite doesn't seem to stop moving
Instead, I want a piece of code which can stop the sprite for a while until the energy bar is 1 or more
This same problem goes for My Thirsty bar and Hungry Bar
Here is my code:
when green flag clicked
hide variable [ Thirsty]
hide variable [ Energy]
hide variable [ Hungry]
set [ Thirsty] to [0]
set [ Energy ] to [5]
set [ Hungry] to [0]
forever
if <(Energy) = [0]> then
switch costume to [ monkey2-c]
say [Look, I'm Tired] for (2) secs
say [Don't worry! Some of my energy will come back after 20 secs] for (2) secs
say [Just don't make me do any energy-consuming activities, okay? ] for (2) secs
end
wait (15) secs
change [ Hungry] by (1)
wait (5) secs
change [ Thirsty] by (1)
wait (20) secs
change [ Energy] by (1)

end
CrazyCreeper380
Scratcher
9 posts

How to add an ending script (check the message for more information)

CrazyCreeper380 wrote:

Hi There.
I need help with my project, Virtual Pet
When my Energy bar is equal to 0, the sprite doesn't seem to stop moving
Instead, I want a piece of code which can stop the sprite for a while until the energy bar is 1 or more
This same problem goes for My Thirsty bar and Hungry Bar
Here is my code:
when green flag clicked
hide variable [ Thirsty]
hide variable [ Energy]
hide variable [ Hungry]
set [ Thirsty] to [0]
set [ Energy ] to [5]
set [ Hungry] to [0]
forever
if <(Energy) = [0]> then
switch costume to [ monkey2-c]
say [Look, I'm Tired] for (2) secs
say [Don't worry! Some of my energy will come back after 20 secs] for (2) secs
say [Just don't make me do any energy-consuming activities, okay? ] for (2) secs
end
wait (15) secs
change [ Hungry] by (1)
wait (5) secs
change [ Thirsty] by (1)
wait (20) secs
change [ Energy] by (1)

end
Please tell me some code which I can add inside the
if <> then

end
block
Bestbuster
Scratcher
40 posts

How to add an ending script (check the message for more information)

CrazyCreeper380 wrote:

CrazyCreeper380 wrote:

Hi There.
I need help with my project, Virtual Pet
When my Energy bar is equal to 0, the sprite doesn't seem to stop moving
Instead, I want a piece of code which can stop the sprite for a while until the energy bar is 1 or more
This same problem goes for My Thirsty bar and Hungry Bar
Here is my code:
when green flag clicked
hide variable [ Thirsty]
hide variable [ Energy]
hide variable [ Hungry]
set [ Thirsty] to [0]
set [ Energy ] to [5]
set [ Hungry] to [0]
forever
if <(Energy) = [0]> then
switch costume to [ monkey2-c]
say [Look, I'm Tired] for (2) secs
say [Don't worry! Some of my energy will come back after 20 secs] for (2) secs
say [Just don't make me do any energy-consuming activities, okay? ] for (2) secs
end
wait (15) secs
change [ Hungry] by (1)
wait (5) secs
change [ Thirsty] by (1)
wait (20) secs
change [ Energy] by (1)

end
Please tell me some code which I can add inside the
if <> then

end
block
Ummm where is the movement script

Last edited by Bestbuster (Oct. 11, 2021 07:19:04)

Bestbuster
Scratcher
40 posts

How to add an ending script (check the message for more information)

I can be of more help if you share the project
deck26
Scratcher
1000+ posts

How to add an ending script (check the message for more information)

That forever loop is only checking for Energy=0 once every 40 seconds.
CrazyCreeper380
Scratcher
9 posts

How to add an ending script (check the message for more information)

Bestbuster wrote:

I can be of more help if you share the project
here you go
https://scratch.mit.edu/projects/447610770/
CrazyCreeper380
Scratcher
9 posts

How to add an ending script (check the message for more information)

deck26 wrote:

That forever loop is only checking for Energy=0 once every 40 seconds.
I don't understand…
Communist33
Scratcher
74 posts

How to add an ending script (check the message for more information)

The wait blocks to take away hunger/thirst inside the loop are making the game wait to check for the energy level
yahaynew
Scratcher
46 posts

How to add an ending script (check the message for more information)

i have found the issue and will share the code as a remix as I was debugging it
please give credit to me
deck26
Scratcher
1000+ posts

How to add an ending script (check the message for more information)

CrazyCreeper380 wrote:

Bestbuster wrote:

I can be of more help if you share the project
here you go
https://scratch.mit.edu/projects/447610770/
Because you do this

forever
if something
end if
wait 40 seconds with occasional variable changes
end

So how can the loop check the value without waiting 40 seconds between checks?
ScratchCloudYT
Scratcher
1 post

How to add an ending script (check the message for more information)

accident

Last edited by ScratchCloudYT (Feb. 22, 2023 11:19:13)

Powered by DjangoBB