This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-14 00:38:42

jedidiahzhu
Scratcher
Registered: 2011-01-16
Posts: 85

Day-Night Cycle

I am creating an RPG called Questopolis. It's quite typical: monsters spawn at night, you can fight them, you earn experience, etc.

I need the monsters to spawn at night and to disappear at day. So I have created a variable called "light", to determine when the monsters need to appear.

The stage also needs to darken and lighten, so this is the script I have right now:

when I receive [started v]
forever
repeat (100)
change [brightness v] effect by (-1)
change [light v] by (-1)
wait (4) secs
end
repeat (100)
change [brightness v] effect by (1)
change [light v] by (1)
wait (2) secs
end
end
This script used to work just fine. But as my RPG expanded, I added an inn. When you slept in the inn, the light level would increase back to maximum. The script to do this looks something like this:

when I receive [sleep v]
set [light v] to (100)
However, this script can't change the stage's brightness. So when you finish sleeping, the sky is still dark.

What changes should I make to these scripts? I would appreciate it if you could help.

-jedidiahzhu

Note: If you would like to check out the project, go to: http://scratch.mit.edu/projects/jedidiahzhu/2977230

Offline

 

#2 2012-12-14 10:25:52

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Day-Night Cycle

You simply forgot to set the brightness back again. c: You can do a quick fix on that "sleep" script:

when I receive [sleep v]
set [light v] to (100)
set [brightness v] effect to (0)
broadcast [started v] //I suggest you restart the day/night cycle, to avoid bugs.


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#3 2012-12-14 11:19:39

Snowdrift
Scratcher
Registered: 2011-06-22
Posts: 500+

Re: Day-Night Cycle

change [brightness v] effect by (light)

Offline

 

#4 2012-12-14 11:38:46

Fordark
Scratcher
Registered: 2010-08-02
Posts: 100+

Re: Day-Night Cycle

Snowdrift wrote:

change [brightness v] effect by (light)

Actually, change the light variable and set the brightness to that

change [light v] by (1)
set [brightness v] effect to (light)


http://dl.dropbox.com/u/34855482/Fordarksig.png

Offline

 

#5 2012-12-14 12:55:51

jedidiahzhu
Scratcher
Registered: 2011-01-16
Posts: 85

Re: Day-Night Cycle

technoguyx wrote:

You simply forgot to set the brightness back again. c: You can do a quick fix on that "sleep" script:

when I receive [sleep v]
set [light v] to (100)
set [brightness v] effect to (0)
broadcast [started v] //I suggest you restart the day/night cycle, to avoid bugs.

Thanks. The problem with that is that almost ALL the sprites are commanded by the "started" message. I'll simply make a new one.

-5 min later-

Great! It works! Thanks!

Offline

 

Board footer