Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Is there a simple script for a morning, noon, evening & night cycle like:
I'm basically making a game using image maps so the character can move from room to room by clicking on a door or something like that.
That part I have figured out, what I don't know however is how to make it so when the character enters a room an event starts, then, once that even is finished he can go in the same room and they'll be another even, but i only want the events to start during a set time of the day ( Morning, Noon ect ect )
I also want to make it so it cycles, so it starts at "Day 01 - Morning", then it goes to Noon, evening, night and when it's back to Morning, it changes to "Day 02 - Morning"
viewtopic.php?t=45886
Presumably using this:
viewtopic.php?f=51&t=46143&p=467483#p467483
Muchos Gracias.
I'm basically making a game using image maps so the character can move from room to room by clicking on a door or something like that.
That part I have figured out, what I don't know however is how to make it so when the character enters a room an event starts, then, once that even is finished he can go in the same room and they'll be another even, but i only want the events to start during a set time of the day ( Morning, Noon ect ect )
I also want to make it so it cycles, so it starts at "Day 01 - Morning", then it goes to Noon, evening, night and when it's back to Morning, it changes to "Day 02 - Morning"
viewtopic.php?t=45886
Presumably using this:
viewtopic.php?f=51&t=46143&p=467483#p467483
Muchos Gracias.
Last edited by advance2 on Thu Apr 12, 2018 6:35 pm, edited 1 time in total.
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Here's one weird way of approaching it that I just put together.
The advance label moves the time of day forward by one. It does this by moving the first item of your time of day list to the end, thus making the first item on the list your current time: time_of_day[0]
I added an end_of_day variable to state whether it's the end of the day or not, so advancing time again will increment the day by one.
So if you end up deciding that you want to add more time of day to your game, e.g. early morning, afternoon, etc. you can just add it to the list.
If you want to advance time multiple times, you add a number into the call and it'll increment the time so many times - see the code for example
It may not be the best way to do it, but for a really simple way of creating a day cycle.
The advance label moves the time of day forward by one. It does this by moving the first item of your time of day list to the end, thus making the first item on the list your current time: time_of_day[0]
I added an end_of_day variable to state whether it's the end of the day or not, so advancing time again will increment the day by one.
So if you end up deciding that you want to add more time of day to your game, e.g. early morning, afternoon, etc. you can just add it to the list.
If you want to advance time multiple times, you add a number into the call and it'll increment the time so many times - see the code for example
It may not be the best way to do it, but for a really simple way of creating a day cycle.
Code: Select all
default day = 1
default time_of_day = ["morning", "noon", "evening", "night"] # edit this list to rename, add or delete time of days
define end_of_day = "night" # set this as the last time of day before new day begins
#default end_of_day = time_of_day[-1] # this can automatically pick up the last element of time_of_day as above, remove above line if you want to use this.
label start:
"Day [day] [time_of_day[0]]"
call advance() # advances time by 1 unit
"Day [day] [time_of_day[0]]"
call advance(2) # advances time by 2 units
"Day [day] [time_of_day[0]]"
return
label advance(increment = 1):
python:
while increment > 0:
if time_of_day[0] == end_of_day:
day += 1
time_of_day.append(time_of_day.pop(0))
increment -= 1
return
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Muchos Gracias Senor. Really amazing.
Is there a way to count weekdays?
And how to make it so when the character enters a room an event starts, then, once that even is finished he can go in the same room and they'll be another even, but i only want the events to start during a set time of the day ( Morning, Noon ect ect )
if statement?
Is there a way to count weekdays?
And how to make it so when the character enters a room an event starts, then, once that even is finished he can go in the same room and they'll be another even, but i only want the events to start during a set time of the day ( Morning, Noon ect ect )
if statement?
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
The code includes comments after the # signs, have you read them? I advanced the time by 2 in the second advance statement as an example if you ever needed to jump further forward in time.
Yes you’ll need if statements to check what time of day it is (if time_of_day[0] == “morning”) for example.
Have you read through the renpy documentations about labels and control flow? It’ll be how you go about doing the room events. Give that a try first and show us your code if you get stuck - it’s harde to give you an example for that as it’s less a general concept and actual game flow.
Yes you’ll need if statements to check what time of day it is (if time_of_day[0] == “morning”) for example.
Have you read through the renpy documentations about labels and control flow? It’ll be how you go about doing the room events. Give that a try first and show us your code if you get stuck - it’s harde to give you an example for that as it’s less a general concept and actual game flow.
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Back on computer now and saw that you mentioned weekdays as well. To simplify how you get the day, time of day and weekday I've incorporated them all into a single object, so you can just get any time component with a simple call.
What you want to do about rooms I'm still going to let you figure out as they're relatively simple with labels and if statements - again if you get stuck let us know and we can help.
What you want to do about rooms I'm still going to let you figure out as they're relatively simple with labels and if statements - again if you get stuck let us know and we can help.
Code: Select all
init python:
class day_time(object):
def __init__(self):
self.day = 1 # set this to whatever starting day is
self.weekdays = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] # arrange these so first weekday goes first
self.time_of_day = ["morning", "noon", "evening", "night"] # add or remove to increase time of day slots
self.end_of_day = self.time_of_day[-1] # automatically picks last slot as end of day
@property
def weekday(self):
return self.weekdays[(self.day-1)%7]
@property
def time(self):
return self.time_of_day[0]
def advance(self, increment = 0, days = 0):
if not (increment + days): # no input
increment = 1
if days: # add to increment by length of time_of_day
increment += days * len(self.time_of_day)
while increment > 0: # loop through increments to shift timeslot and days forward
if self.time_of_day[0] == self.end_of_day:
self.day += 1
self.time_of_day.append(self.time_of_day.pop(0))
increment -= 1 # reduce incrememnt to escape loop after enough runs
default clock = day_time()
label start:
"{b}clock.day{/b} returns Day: {b}[clock.day]{/b}"
"{b}clock.weekday{/b} returns Weekday: {b}[clock.weekday]{/b}"
"{b}clock.time{/b} returns Time of Day: {b}[clock.time]{/b}"
"{b}$ clock.advance(){/b} advances time"
$ clock.advance() # advances time by one slot
"Advanced 1 slot:\n\nDay [clock.day] ([clock.weekday]) [clock.time]"
$ clock.advance(2) # advances time by two slots
"Advanced 2 slots:\n\nDay [clock.day] ([clock.weekday]) [clock.time]"
$ clock.advance(days=1) # advances one day
"Advanced 1 day:\n\nDay [clock.day] ([clock.weekday]) [clock.time]"
$ clock.advance(1,8) # advance 8 days and one slot
"Advanced 1 slot and 8 days (note night to morning still advances addition day):\n\nDay [clock.day] ([clock.weekday]) [clock.time]"
return
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Mushos Gracias again.
I used the same if statement and it worked well.
I want to have several rooms, in which, dependig on time the different picture is shown, and to have a button to advance time by 1 period of day, morning to noon, noon to evening etc.
The code would go like (I don't know how to post code here):
screen room_evening:
imagemap:
idle " room evening"
hover " room evening hotspot"
hotspot (44, 238, 93, 93) action Jump("swimming") alt "Swimming"
hotspot (360, 62, 93, 93) action Jump("science") alt "Science"
hotspot (726, 106, 93, 93) action Jump("art") alt "Art"
hotspot (934, 461, 93, 93) action Jump("home") alt "Home"
screen room_weekend_morning:
imagemap:
idle " room weekend morning"
hover " room weekend morning hotspot"
hotspot (44, 238, 93, 93) action Jump("swimming2") alt "Swimming2"
hotspot (360, 62, 93, 93) action Jump("science2") alt "Science2"
hotspot (726, 106, 93, 93) action Jump("art2") alt "Art2"
hotspot (934, 461, 93, 93) action Jump("home2") alt "Home2"
label start:
scene main room default
if time_of_day[0] == "evening":
if days are mon to fri:
call screen room_evening
if time_of_day[0] == "morning":
if saturday, sunday:
call screen room_weekend_morning
else
show main room default picture
Each picture of room is imagemap. I want to show time in upper left/right corner and button to advance time by period of day.
I used the same if statement and it worked well.
I want to have several rooms, in which, dependig on time the different picture is shown, and to have a button to advance time by 1 period of day, morning to noon, noon to evening etc.
The code would go like (I don't know how to post code here):
screen room_evening:
imagemap:
idle " room evening"
hover " room evening hotspot"
hotspot (44, 238, 93, 93) action Jump("swimming") alt "Swimming"
hotspot (360, 62, 93, 93) action Jump("science") alt "Science"
hotspot (726, 106, 93, 93) action Jump("art") alt "Art"
hotspot (934, 461, 93, 93) action Jump("home") alt "Home"
screen room_weekend_morning:
imagemap:
idle " room weekend morning"
hover " room weekend morning hotspot"
hotspot (44, 238, 93, 93) action Jump("swimming2") alt "Swimming2"
hotspot (360, 62, 93, 93) action Jump("science2") alt "Science2"
hotspot (726, 106, 93, 93) action Jump("art2") alt "Art2"
hotspot (934, 461, 93, 93) action Jump("home2") alt "Home2"
label start:
scene main room default
if time_of_day[0] == "evening":
if days are mon to fri:
call screen room_evening
if time_of_day[0] == "morning":
if saturday, sunday:
call screen room_weekend_morning
else
show main room default picture
Each picture of room is imagemap. I want to show time in upper left/right corner and button to advance time by period of day.
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Put your code in between code tags to preserve coding indentation. So [ code ] your code here [ /code ] without the spaces will work.
https://www.renpy.org/doc/html/screen_actions.html
As for:
This is tricky to teach but you need to learn some basic python syntax and condition statements. Ren'py documentation has some basics of how to handle if else: https://www.renpy.org/doc/html/conditional.html
Also, the code I last gave you handles time of day completely differently. Please run that code and read the comments to see how to use it Your code above simply isn't referencing the right variables!
Have another go and let us know how you get on! I'm trying to help you learn how coding works so that we won't end up writing the whole game for you, but the only way is if you try and gradually learn how individual coding principles works. Get small things to work at a time, then expand on it, and eventually you can do anything!
You just need to add a button (textbutton will work but you can use imagebutton if you want) and have it trigger a label with the code to advance the time. The Call() action can achieve that for you:I want to show time in upper left/right corner and button to advance time by period of day.
https://www.renpy.org/doc/html/screen_actions.html
Code: Select all
textbutton "Advance time" action Call("label_you_need_to_name")
Code: Select all
if time_of_day[0] == "evening":
if days are mon to fri:
call screen room_evening
if time_of_day[0] == "morning":
if saturday, sunday:
call screen room_weekend_morning
else
show main room default picture
Also, the code I last gave you handles time of day completely differently. Please run that code and read the comments to see how to use it Your code above simply isn't referencing the right variables!
Have another go and let us know how you get on! I'm trying to help you learn how coding works so that we won't end up writing the whole game for you, but the only way is if you try and gradually learn how individual coding principles works. Get small things to work at a time, then expand on it, and eventually you can do anything!
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
I think I have not explained properly.
what I wanted to say is
Sorry for the confusion that I made. What i wanted to show/say is that I need 2 conditions for picture/imagemap to be shown, period od day and day of the week.
what I wanted to say is
Code: Select all
if time_of_day[0] == "evening": #this is actual code, also shows what i want to condition
if days are mon to fri: #this is not a code it is what i want to achive, to make condition for mon to fri
call screen room_evening #this is actual code again, just to show what i want to achive
if time_of_day[0] == "morning": #actual code
if saturday, sunday: #not code, its what i want to make, condition for day of the week
call screen room_weekend_morning # actual code,
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
That's ok, I was just trying to say a couple of things in my last comments:
- you probably need to gain a bit of general programming language, particularly in python, so that you can figure out the actual code - as it'll help you figure out more coding in the future. That's why I don't want to just give you the code for that right now.
- the variable you're using is no longer correct (in the actual code). The last version I gave you uses clock.time not time_of_day[0] to get the time of day
- you probably need to gain a bit of general programming language, particularly in python, so that you can figure out the actual code - as it'll help you figure out more coding in the future. That's why I don't want to just give you the code for that right now.
- the variable you're using is no longer correct (in the actual code). The last version I gave you uses clock.time not time_of_day[0] to get the time of day
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Man You are the best.I have figured it all out. Muchos Gracias again. The question I have now is:
Is there a more simple way to jump time or image like
textbutton "{b}[clock.time]{/b} {b}[clock.weekday]{/b}" action Call $ clock.advance()
or
hotspot (670, 170, 93, 93) action call screen hallway
instead of going to label, than to $ clock.advance() or call screen hallway?
Again Muchos Gracias.
Code: Select all
screen room:
imagemap:
vbox:
textbutton "{b}[clock.time]{/b} {b}[clock.weekday]{/b}" action Call("roomtime")
if clock.time == "Night":
idle " room night"
hover "room hover"
else:
idle " room"
hover "room hover"
hotspot (670, 170, 93, 93) action Jump("hallway")
label roomtime:
$ clock.advance()
call screen room
label hallway:
call screen hallway
textbutton "{b}[clock.time]{/b} {b}[clock.weekday]{/b}" action Call $ clock.advance()
or
hotspot (670, 170, 93, 93) action call screen hallway
instead of going to label, than to $ clock.advance() or call screen hallway?
Again Muchos Gracias.
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
I'm still struggling a bit with the screen language myself, but I think I have the answer for the first question:
To advance time, use the screen action Function():
https://www.renpy.org/doc/html/screen_a ... l#Function
Not tested:
Second part, apparently you can't call a screen from within a screen. It causes problems - so if someone else can shed light on this that'd be great.
To advance time, use the screen action Function():
https://www.renpy.org/doc/html/screen_a ... l#Function
Not tested:
Code: Select all
textbutton "{b}[clock.time] [clock.weekday]{/b}" action Function(clock.advance())
Second part, apparently you can't call a screen from within a screen. It causes problems - so if someone else can shed light on this that'd be great.
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Tested, not working when you replace action Call("roomtime") with action Function(clock.advance()).
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Function( clock.advance, 7 ) ... no need the (), just the function/method name then any arguments and keywords.
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
Hehe, the one time I don't test my code
Re: Simple script for a day/night cycle, or rather a morning, noon, evening & night cycle
I included your script on my game @kivik, functions great but i'm wondering if there is an easy way to manage events with it beisdes the usual if/else?
Simple code I made so the player can't sleep unless he done the intro events, is my only option to add "and variable" for every new events where I want the player to not sleep until he finishes it?
I'm new to coding so any suggestion would be great.
Simple code I made so the player can't sleep unless he done the intro events, is my only option to add "and variable" for every new events where I want the player to not sleep until he finishes it?
I'm new to coding so any suggestion would be great.
Code: Select all
label sleepbed:
menu:
mc "What do I do now?"
"Take a nap.":
$ clock.advance()
mc "I feel great now, it's already {b}[clock.time]{/b}"
jump bed
"Sleep until next day.":
if clock.time == "Morning" and kitchenintro == "no":
$ clock.advance(4)
jump bed
elif clock.time == "Noon" and kitchenintro == "no":
$ clock.advance(3)
jump bed
elif clock.time == "Evening" and kitchenintro == "no":
$ clock.advance(2)
jump bed
elif clock.time == "Night" and kitchenintro == "no":
$ clock.advance(1)
jump bed
mc "Woah I slept too much, wait what day are we? oh it's {b}[clock.weekday]{/b}"
jump bed
else:
mc "I can't sleep now I have things to do"
jump bed
"Do nothing":
jump bed
Last edited by xplosion on Sat Aug 04, 2018 10:16 am, edited 1 time in total.
Who is online
Users browsing this forum: Google [Bot]