Play events by day (quick mode)

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
User avatar
Miko-Class Veteran
Posts: 686
Joined: Mon Jan 26, 2009 7:21 pm

Play events by day (quick mode)

#1 Post by gas » Wed Apr 18, 2018 2:52 pm

PLAY EVENTS BY DAY (quick mode, call expression example)
This is not a recipe, but mostly a code snippet I'm using often. Is quite convenient.

Code: Select all

default day=0
default schedule=[3,7]

label start:
    "Welcome to a looping game!"
label cycle:
    $ day +=1
    "It's day [day]."
    if day in schedule:
        $ lbl="event"+str(day)
        call expression lbl
    jump cycle
label event3:
    "This is the event that happen at day 3!"
label event7:
    "This is the event that happen at day 7!"
How it work.
At first, we have a variable that store the actual day (turn, phase, whatever).
Then we have a list of days into wich an event will occurr (in my example, 3 and 7).
In the code, we check if the actual day value is present in that list of candidates. It's a very fast check. If the value is present, you create a string composed by the word "event" + the string version of the day number.
So, for example, day 23 will become "event23".
Now, thanks to call expression, we can call that label name we've composed.
!!NOTE: a simple 'call' doesn't work, in that given case it go search for the 'lbl' label, that doesn't exist.
'call expression' consider instead what follow as an expression to evaluate, not the actual label name.

The events have as labels the word "event" then the day into wich they happen.
Just remember to use return at the end of the event to jump back to the main routine.

EXTRA: you can have fun creating more than one schedule (maybe for night events), checks and kind of events. This could create quite a complex story.
So, for example, a list of nightly events:

Code: Select all

default nightly=[5,11]
...another check...

Code: Select all

    if day in nightly:
        $ lbl="night"+str(day)
        call expression lbl
...and finally create events labels, as 'night5' and 'night11'.

Code: Select all

label night5:
    "Before going to sleep, I want to play some more!"
label night11:
    "A man in red ate all my cookies!"
Being creative, you can surely find a way to trigger events based on scores, having a date with just the higher loved girl, and find how to have an event play just once (hint: you can remove elements from a list at will...).
10 ? "RENPY"
20 GOTO 10


User avatar
Miko-Class Veteran
Posts: 613
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA

Re: Play events by day (quick mode)

#2 Post by wyverngem » Wed Apr 18, 2018 10:32 pm

Thanks for sharing. :D I wish I had known about this when I had first started renpy. Would have saved a lot of time. :)

Posts: 14
Joined: Sat Feb 17, 2018 8:58 am

Re: Play events by day (quick mode)

#3 Post by KingsCard » Fri Apr 20, 2018 3:49 am

Thank you !

User avatar
Posts: 22
Joined: Mon Aug 01, 2016 9:58 am
Tumblr: wingcinna
Location: US

Re: Play events by day (quick mode)

#4 Post by wingcinna » Tue May 01, 2018 12:45 am

awesome! thank you~
Working on: sci-fi sprites and another project with Owl

Post Reply

Who is online

Users browsing this forum: No registered users