Help with DSE GUI coding

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
Jinnai
Regular
Posts: 36
Joined: Tue Oct 07, 2003 7:32 pm
Contact:

Help with DSE GUI coding

#1 Post by Jinnai »

I'm having trouble writing a GUI for the game i'm designing. If I can get past this, it should be okay.

I have figured out the basics I think, but still have some questions. For certain:

1. I found a thread for making a calander, which solves one question, but how does one keep track of days and display them as "June 6th" as opposed to "Day 23"

2. How can i force a particular part of day to be unchangable/unselectable on various days? FE: School in morning slot? Can it work both with existing choices normally available and choices not normally available?

3. Can you add/remove choices depending on circumstances as to what the player can chose?

4. Is it possible to bypass the gui on various days leaving the player with no choices, or have events that fire before the day begins (after night block fires)

5. Can you disable saving/loading except in the GUI menu?


Thanks.
)'.'(
Power of Sqyishyness!!

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Help with DSE GUI coding

#2 Post by PyTom »

Jinnai wrote: 4. Is it possible to bypass the gui on various days leaving the player with no choices, or have events that fire before the day begins (after night block fires)
Yes, look at the code in main.rpy that is run for each period of the day. You can add more periods in a similar manner... and note that the day planner is more-or-less independent from the event_dispatcher.

The rest of what you want is possible, but would require a rewrite of the day planner. I'd be willing to do that if you can show to me a mostly complete game, one that's likely to be finished.

Adding more periods is the only thing that needs to be done early in the development process, which is why I mention it here... ask if you have a problem getting it working.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

shaja
Regular
Posts: 73
Joined: Sun Oct 16, 2005 8:34 am
Contact:

Re: Help with DSE GUI coding

#3 Post by shaja »

Jinnai wrote: 1. I found a thread for making a calander, which solves one question, but how does one keep track of days and display them as "June 6th" as opposed to "Day 23"
If you're not going to have a particularly large number of days, it's probably simplest to just type up the day number -> day name relations into a dictionary, such as:

Code: Select all

$ daynamedict = {1:'May 15th', 2:'May 16th', 3:'May 17th }
...and so on, and, and then:

Code: Select all

$ dayname = daynamedict[day]
"It's %(dayname)s."
Otherwise, a more general solution is to use the python datetime module.

Code: Select all

init:
        python:
            import datetime
            def ordinalth(n):    # from Simon Willison
                t = 'th st nd rd th th th th th th'.split()
                if n % 100 in (11,12,13):
                    return '%dth' % n
                return str(n) + t[n % 10]
            def getDate(day):
                basedate = datetime.date(2006,5,14) # The day before day 1
                adjdate = basedate + datetime.timedelta(days=day)
                return adjdate.strftime("%B ") + ordinalth(adjdate.day)

Code: Select all

$ dayname = getDate(day)
"It's %(dayname)s."

Jinnai
Regular
Posts: 36
Joined: Tue Oct 07, 2003 7:32 pm
Contact:

Re: Help with DSE GUI coding

#4 Post by Jinnai »

PyTom wrote:Adding more periods is the only thing that needs to be done early in the development process, which is why I mention it here... ask if you have a problem getting it working.
No, I don't think I need that. I don't intend as far as I can envision to change the number of periods available, just at certain points make certain choices unchangable in certain periods for the player, similar to what is done in True Love with going to school.
)'.'(
Power of Sqyishyness!!

Jinnai
Regular
Posts: 36
Joined: Tue Oct 07, 2003 7:32 pm
Contact:

Re: Help with DSE GUI coding

#5 Post by Jinnai »

shaja wrote:
Jinnai wrote: 1. I found a thread for making a calander, which solves one question, but how does one keep track of days and display them as "June 6th" as opposed to "Day 23"
Otherwise, a more general solution is to use the python datetime module.

Code: Select all

init:
        python:
            import datetime
            def ordinalth(n):    # from Simon Willison
                t = 'th st nd rd th th th th th th'.split()
                if n % 100 in (11,12,13):
                    return '%dth' % n
                return str(n) + t[n % 10]
            def getDate(day):
                basedate = datetime.date(2006,5,14) # The day before day 1
                adjdate = basedate + datetime.timedelta(days=day)
                return adjdate.strftime("%B ") + ordinalth(adjdate.day)

Code: Select all

$ dayname = getDate(day)
"It's %(dayname)s."
This is actually what I'm looking for moreof as I plan to make this an ongoing game without any defined end (probably). Ifso, how do you add a february 29 ever 4 years (since I don't have defined years I'd just be numbering Year 1, Year 2) or by the player's age.

And actually while i'm at it...is it possible to make a code to have the character pick his age and use it ingame for an event?
)'.'(
Power of Sqyishyness!!

shaja
Regular
Posts: 73
Joined: Sun Oct 16, 2005 8:34 am
Contact:

Re: Help with DSE GUI coding

#6 Post by shaja »

Jinnai wrote:This is actually what I'm looking for moreof as I plan to make this an ongoing game without any defined end (probably). Ifso, how do you add a february 29 ever 4 years (since I don't have defined years I'd just be numbering Year 1, Year 2) or by the player's age.
The datetime functions account for leap years automatically.
It would also be easy to get a year to print, or to change the getDate function to return (for example) "June 12th, 2006".
Jinnai wrote:And actually while i'm at it...is it possible to make a code to have the character pick his age and use it ingame for an event?
As simple as putting menus up to pick year, month and day, I'd imagine.

Regarding your wanting to have specific choices available on specific days, PyTom actually made it easy to add some code for that into his framework.

For example, in day_planner.rpy, rename the dp_period_acts dictionary to dp_period_default_acts, and add a new dictionary dp_period_special_acts like so:

Code: Select all

        # A map from the period names to a list of the activities
        # available for that period. This may be conputed before
        # each call to day_planner. Each entry is a tuple, where
        # the first element is the name shown to the user, and the
        # second is the name assigned to the variable for that
        # period.
        
        # shaja: renamed dp_period_acts to dp_period_default_acts
        dp_period_default_acts = {        
            'Morning': [
            ( 'Attend Class', "class" ),
            ( 'Cut Class', "cut"),
            ],
            
            'Afternoon': [
            ( 'Study', "study" ),
            ( 'Hang Out', "hang" ),
            ],
            
            'Evening' : [
            ( 'Exercise', "exercise" ),
            ( 'Play Games', "play" ),
            ],
            }
            
        dp_period_special_acts = {
            # For day 3, require class in the morning
            3: { 'Morning':[('School required', "class")],
                'Afternoon':[( 'Study', "study" ), ( 'Hang Out', "hang" )],
                'Evening':[( 'Exercise', "exercise" ), ( 'Play Games', "play" )]
                }
            }
...and then change main.rpy to check the special acts dictionary for the current day, and use the default if today isn't special.

Code: Select all

    # Here, we want to set up some of the default values for the
    # day planner. In a more complicated game, we would probably
    # want to add and remove choices from the dp_ variables
    # (especially dp_period_acts) to reflect the choices the
    # user has available to him.
    
    # shaja: get the daily planner acts for the day, use defaults if today's day
    # number isn't in the dictionary
    $ dp_period_acts = dp_period_special_acts.get(day, dp_period_default_acts)

    $ morning_act = None
    $ afternoon_act = None
    $ evening_act = None
With just these changes, limiting or changing the choices for a day is possible, but you'd still have to click on the (potentially) one choice available for a period.
It's certainly possible to make the code more complex so that things work exactly as you envision them, but you get the idea, anyway.

Jinnai
Regular
Posts: 36
Joined: Tue Oct 07, 2003 7:32 pm
Contact:

#7 Post by Jinnai »

Thanks. I think once I can get the GUI figured out overall the rest will be simple for me. I've done scripting for other games (Europa Universalis 2 and Crusader Kings if anyone knows them) so once I get a GUI done, the rest seems easy.

Except i'd need an artist or have all my images based on rips. I might be able to do backgrounds myself, but without a tablet...
)'.'(
Power of Sqyishyness!!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], henne