Have characters greet you at game launch

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
Message
Author
User avatar
gas
Miko-Class Veteran
Posts: 718
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Have characters greet you at game launch

#1 Post by gas » Mon Apr 16, 2018 3:22 pm

HAVE CHARACTERS GREET AT GAME LAUNCH
This easy recipe allow for characters to greet you at game launch, as for Tokimeki Memorial 3, BEFORE the main menu.
It also show how you can use the internal device clock ("locale") to differentiate events between night and day.

At first we import time module, that contain gmtime (get the device time) and strftime (it turn the time into a readable string format).
We check if the game has been launched at least once, if not the whole greeting phase is dropped.
This is a basic check, in more advanced code you'll want to display the main character of the last ending reached, or the higher love score owner. !!You need to use a persistent variable!! So for example a persistent that register the last ending reached or the actual love scores.
Then we turn the time value (abstract) stored in gmtime() into a readable string thanks to strftime(), and put it into the 'hour' variable.
Strftime have a lot of possible arguments, in this given case we'll use just "H%", the hours.
Here's a list of most common directives.
%a Locale’s abbreviated weekday name.
%A Locale’s full weekday name.
%b Locale’s abbreviated month name.
%B Locale’s full month name.
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%I Hour (12-hour clock) as a decimal number [01,12].
%j Day of the year as a decimal number [001,366].
%m Month as a decimal number [01,12].
%M Minute as a decimal number [00,59].
%p Locale’s equivalent of either AM or PM.
%S Second as a decimal number [00,61].
%y Year without century as a decimal number [00,99].
%Y Year with century as a decimal number.
so you can write something like...

Code: Select all

    $ vari=strftime("%A, %B %d. %I:%M", gmtime())
    e "[vari]"
and eileen will say something like
"Monday, February 25. 9:45"
** Remember you have to IMPORT the strftime and gmtime modules at init phase, or this doesn't work and throw an error.

Strftime always return strings, not numbers (hour="11", that's not the number 11 but a string of text, so no possible math operations)... Using an int() method we cheat the system and change it into an integer.
What's left is to decide what to show based on that integer.

Code: Select all

init python:
    import time
label splashscreen:
    # greet the player based on daytime
    # ... but only if you launched the game at least once before!
    if persistent.launched==None:
        return
    scene bg room
    $ hour=time.strftime("%H",time.gmtime()) 
    $ hour=int(hour) 
    if hour >8 and hour <22:
        show eileen happy
        e "Good morning! I was waiting for you! Let's have fun together!"
    else:
        show eileen sleepy
        e "Yawn... You're really all about me, but please try to sleep in a while!"
    return
label start:
    $ persistent.launched=True
    e "That's my game!"
    return
Feel free to ask if you're lost.
SOME NOTE
Use quick and small tenses, that's just a candy and the player is feeling the urge of begin a new game!
Reloading the game when developing could have this scene repeat. Don't mind, it doesn't happen in a distributed game.
The lack of the quick menu is intentional, proper and necessary. The game is not actually started, you can't save or set options.
You can display WHATEVER, included images, animations and any screen.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll be not notified about.

10 ? "RENPY"
20 GOTO 10

RUN

PrinnyBaal
Newbie
Posts: 3
Joined: Thu Apr 05, 2018 4:22 pm
Contact:

Re: Have characters greet you at game launch

#2 Post by PrinnyBaal » Tue Apr 17, 2018 10:51 am

oo, this is super cool. Thanks I'm looking forward to playing around with this!

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Have characters greet you at game launch

#3 Post by kivik » Tue Apr 17, 2018 1:20 pm

Very cool idea! Made me think of doing something with my start up screen :)

Hseo
Regular
Posts: 33
Joined: Thu Sep 24, 2009 10:42 am
Completed: High School Life:HSL
Deviantart: greeeed
Contact:

Re: Have characters greet you at game launch

#4 Post by Hseo » Mon Jul 23, 2018 11:00 am

Thanks again ^-^

Post Reply

Who is online

Users browsing this forum: No registered users