(Solved) Triggering events during certain times of the day

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Post Reply
Message
Author
JaxxyLupei
Regular
Posts: 30
Joined: Tue Apr 08, 2014 10:34 pm
Projects: Dance With Me? (A date sim)
Location: NY

(Solved) Triggering events during certain times of the day

#1 Post by JaxxyLupei »

Hello again ren'py forums, I've come with a new dilemma.

During the weekends in our games, the player has a choice to explore different areas of the town (mall+various stores inside, movies, park, fast food place, etc) and because it's a date sim, the player also has a choice to interact with different girls they come across.

We want a system where the girls can only appear in a location at a certain time of the day. For example, like in WinterWolves' game "Always Remember Me", the player can go to the mall, walk into a certain store and talk to one of the eligible guys, but only if it's a certain time of day.

In shorter terms, Girl A appears in the food court at noon to afternoon but won't be around during Dusk. Instead, Girl B will be there, or none at all.

We already have our day phases set in (Dawn, Morning, Noon, Afternoon, Dusk, Night), the calendar code taken and modified from http://lemmasoft.renai.us/forums/viewto ... 51&t=22393.
Last edited by JaxxyLupei on Sun Jul 05, 2015 11:32 pm, edited 1 time in total.

User avatar
kitsalai
Regular
Posts: 65
Joined: Wed Jan 08, 2014 11:05 pm
Projects: Imaginatum
Location: US
Contact:

Re: Triggering events during certain times of the day

#2 Post by kitsalai »

You can use python's time class: https://docs.python.org/2/library/time. ... e.strftime

For example:

Code: Select all

init python:
    import time

label start:
    $day = time.strftime("%a")
    if day == "Sun" or day == "Sat":
        jump event1
    else:
        jump event2
Just make sure the variable day doesn't conflict with any variables from the cookbook

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Triggering events during certain times of the day

#3 Post by trooper6 »

Kitsalai, your code returns the real time in real life...I think the OP wants to how to make events based on game time, not real time.
JaxxyLupei, use if statements. You go to the shop and when arrive there is a if statement. If it is the game time/day you want, you do the event you want.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
kitsalai
Regular
Posts: 65
Joined: Wed Jan 08, 2014 11:05 pm
Projects: Imaginatum
Location: US
Contact:

Re: Triggering events during certain times of the day

#4 Post by kitsalai »

trooper6 wrote:...
Wow, I completely read that wrong. Sorry about that.

daikiraikimi's calendar class does have a weekday function that returns the day of the week. You can look into that and use if statements as trooper6 said.

JaxxyLupei
Regular
Posts: 30
Joined: Tue Apr 08, 2014 10:34 pm
Projects: Dance With Me? (A date sim)
Location: NY

Re: Triggering events during certain times of the day

#5 Post by JaxxyLupei »

trooper6 wrote:Kitsalai, your code returns the real time in real life...I think the OP wants to how to make events based on game time, not real time.
JaxxyLupei, use if statements. You go to the shop and when arrive there is a if statement. If it is the game time/day you want, you do the event you want.
I've tried the if statements before. Errors galore, unfortunately.

The issue is, we have to manually insert the change time of day in between story advances in our code. Example:

Code: Select all

"It's currently dawn."
$ calendar.next_day_phaze()
"It's now morning!"
It works out great for the story progression, but during the weekends, it hits a neutral time zone because everything the player does on those days is completely optional. The only way I see the if statements working out is if we made all of the meetings with the girls mandatory (which some are depending on previous interactions, but that's besides the point) which we don't want.

Maybe I'm just an idiot and not utilizing them correctly? :oops:

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Triggering events during certain times of the day

#6 Post by trooper6 »

if should work...and it shouldn't matter if you manually insert the change time of day or not. All that matters is that you can check what day and time it is...which I presume you can...or your code wouldn't be working the way you want it to at all. What kind of errors are you getting?
So I assume your calendar has a day variable and a phase variable.
I also assume you have a label for the different stores/places your player can go.

So let's say one place is the candy shop. You want it so that if they go to the candy shop on Saturday afternoon, they meet Olivia, if they go to the candy shop on Sunday morning they meet Brad.

Let us say this is your current candy shop code:

Code: Select all

label candy_shop:
    "You walk in the candy shop."
    "The candy shop owner asks if you would like to buy anything."
All you do is add in the if statements.

Code: Select all

label candy_shop:
    "You walk in the candy shop."
    if calendar.day == 6 and calendar.phaze == "Afternoon":
        "You see Olivia shopping for candy." #You can write the whole scene here or call an Olivia label, or whatever you want.
    if calendar.day == 7 and calendar.phaze == "Morning":
        "You see Brad shopping for candy."#You can write the whole scene here or call a Brad label, or whatever you want.
    "The candy shop owner asks if you would like to buy anything."
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

JaxxyLupei
Regular
Posts: 30
Joined: Tue Apr 08, 2014 10:34 pm
Projects: Dance With Me? (A date sim)
Location: NY

Re: Triggering events during certain times of the day

#7 Post by JaxxyLupei »

Okay, so I see what I did wrong. I was wording the if statements incorrectly before.

So I tried the way you suggested. I've tried both if calendar.day == number and if calendar.day == "day", (just to test it out before inputting the phases) but my script seems to be ignoring it. I've tried it on a store in the mall, for instances where a certain event has to happen. Instead it skips right over it and goes back to the mall menu.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Triggering events during certain times of the day

#8 Post by trooper6 »

You should test to see what day your calendar things it is.
I'd do something like this:

Code: Select all

label candy_shop:
    "You walk in the candy shop."
    "Test: The day is [calendar.day]"
    if calendar.day == 6:
        "You see Olivia shopping for candy." #You can write the whole scene here or call an Olivia label, or whatever you want.
    if calendar.day == 7:
        "You see Brad shopping for candy."#You can write the whole scene here or call a Brad label, or whatever you want.
    "The candy shop owner asks if you would like to buy anything."
See what comes back. Then you'll be able to see if what you think the day is, is what the calendar thinks the day is. Because is designed so that unless it is that day, it won't trigger those events. I don't know what you have in your calendar day variable. I don't know if it is numbers, I don't know if it is names...or if numbers...how the numbers are calculated...for example, is 0 Monday? Is 1 Monday? You'd have to check that out.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Triggering events during certain times of the day

#9 Post by trooper6 »

You are using daikiraikimi's calendar code more or less exactly?

So I went into her code and looked at each of the elements. You should do that yourself, by the way, and make sure you understand each variable and each element. If you know what each thing does, then you'll know how to adapt the code to your needs, or know what to call for an if.

So, for example, if you are using daikiraikimi's code, you don't want to use calendar.day for your if, because that is the day of the month...so a number between 1 and 31. Looking at the code, you want to use calendar.weekday. So I made a test project for you. This works for me using daikiraikimi's code:

Code: Select all

label start:
    $calendar= Calendar()
    show screen calendar()
    "How does this work?"
    call test_event
    $calendar.next()
    "Advancing the day"
    call test_event
    $calendar.next(3)
    "Advancing the day by 3."
    call test_event
    "Test over."
    
    return

label test_event:
    if calendar.weekday == "Tuesday":
        "It is Tuesday!"
    else:
        "It is not Tuesday."
    return
So try your version of:

Code: Select all

label candy_shop:
    "You walk in the candy shop."
    "Test: The day is [calendar.weekday]"
    if calendar.weedday == "Saturday":
        "You see Olivia shopping for candy." #You can write the whole scene here or call an Olivia label, or whatever you want.
    if calendar.weedday == "Sunday":
        "You see Brad shopping for candy."#You can write the whole scene here or call a Brad label, or whatever you want.
    "The candy shop owner asks if you would like to buy anything."
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Triggering events during certain times of the day

#10 Post by Onishion »

See what comes back. Then you'll be able to see if what you think the day is, is what the calendar thinks the day is
You can always use the dev kit for that, just hit shift-d to open the menu and check the variable viewer to see what the variable is set to on any given scene.

JaxxyLupei
Regular
Posts: 30
Joined: Tue Apr 08, 2014 10:34 pm
Projects: Dance With Me? (A date sim)
Location: NY

Re: Triggering events during certain times of the day

#11 Post by JaxxyLupei »

Hm, I guess I should have done that early on...we had someone else implement the code and set up a template for us to follow, but didn't explain all of the nooks and crannies to us.

But I tried weekday and everything ran smoothly. Thank you very much!

Post Reply

Who is online

Users browsing this forum: Google [Bot]