Converting day numbers into days of the week

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
lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Converting day numbers into days of the week

#1 Post by lydia »

As a renpy newbie, hopefully I am explaining my question clearly. My only
coding experience has come with the rags game engine and I'm eager to
try something else. What I'm trying to do is a stat building game. Instead
of day numbers, I would like to have Sunday-Saturday. This because I'd like
to have events for weekends be different from weekday actions. My coding
efforts to this point has been to include: "day" to still track the number of game
days. "Days" to allow for a 1-7 that I use to convert into sunday-saturday. And
wcount to have the variable equal the label of sunday -saturday. Plus using the
variable weekday to provide each day sunday-saturday. I begin with label start:

$ day = 0
$ days = 0
$wcount = 0
$weekname = ['Sun','Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat']
$weekname = 'Sun'

Then call a menu below to advance the weekday from sunday to monday:
menu:
if day <= 1:
$weekname = 'Mon'
jump day
if $wcount = 2:
$weekname = 'Tue'
jump day
if $wcount = 3:
$weekname = 'Wed'
jump day
if $wcount = 4:
$weekname = 'Thu'
jump day
if $wcount = 5:
$weekname = 'Fri'
jump day
if $wcount = 6:
$weekname = 'Sat'




# We jump to day to start the first day.
jump day


And finally to advance the day number by one each day as well as reset the wcount
so it doesn't go beyond 7 to represent the days of the week:

label day:

# Increment the day it is.
$ day += 1
$wcount +=1
$ days += 1

if wcount > 7:
$ wcount = 0

My coding to provide the screen display for day number and day of the week:

label weekname:
#weekname
$wcount = day % 7
$weekday = weekname[wcount]

"It's [$weekname]."
"It's day %(day)d."

Works as far as it does show the day number. But the day of the week doesn't advance from
sunday.

My error message from renpy:

line 202: expected menuitem
if day <= 1:

This a reference to my menu attempt to advance the text from sunday to monday.
Would appreciate some advice on how to correct this coding. Plus what would
probably be an even easier way to do what I am looking for.

Thanks for your patience and any suggestions for coding example links.

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Converting day numbers into days of the week

#2 Post by Showsni »

Welcome to the forum! Firstly, if you use code tags

Code: Select all

 and 
you can oreserve the spacing in your code, so it's easier to troubleshoot.

Looking at your code...
First, you've defined weekname twice, so it will immediately stop being a list and start being just "Sun". Presumably you need the list to be called something else.
You don't want to use menu at all here; menu is only if you want to display a menu to the user.

I see you're using the modulo command % anyway; that propbably makes it unnecessary to use quite so many variables. Maybe the following code:

Code: Select all

    $ day = 0
    $ daynames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
    label today:
        pass
    $ todays =  daynames[(day%7)]
    "It is day [day]. Today is [todays]."
    $ day +=1
    jump today
I suppose to check if it's the weekend you'd then use

Code: Select all

if todays == "Sun" or todays == "Sat":
    #do stuff

lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Re: Converting day numbers into days of the week

#3 Post by lydia »

That you for the post and the coding. This is so much easier than what
I was trying to do. For the weekend, I was looking to provide a different
list of activity choices. So first, I would use your if today code to check
for a weekend. Would I then identify the periods and choices in the same
way that in did in setting up the default theme. Of course providing a different
name so it doesn't override the original code. I'd want to go back to the
same weekday activity choices once the weekend was over.

Code: Select all

# Set up a default theme.
init python:

dp_period("Morning", "morning_act")
    dp_choice("Art Class", "class")
    dp_choice("Cut Class", "cut")
    dp_choice("Vocal Training", "vocal")
    
    dp_period("Afternoon", "afternoon_act")
    dp_choice("Dance Class", "dance")
    dp_choice("Drawing", "drawing")
    dp_choice("Music Lesson", "music")

    dp_period("Evening", "evening_act")
    dp_choice("Exercise", "exercise")
    dp_choice("Shopping", "shop")
    dp_choice("Perform", "perform")
Hope that I used the code function properly to display these items. I
followed the beginner material well enough for renpy. It was clearer
because there was sample code that did what I was also trying to do.
But I didn't have much luck finding a more detailed sample of the proper
use of if statements for example. Thanks again for your assistance.

lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Re: Converting day numbers into days of the week

#4 Post by lydia »

Now I'm trying to implement a unique set of actions in the daily planner for weekend options. Thanks to an assist from Showsni, have managed to introduce new weekend options for the morning time period. The new items display as choices in the planner but I haven't been able to get the associated event text to display. Not getting any error messages, it just doesn't show anything for the morning period. Then you click the screen and the afternoon event displays. Tried to use the same sort of coding that was used for the weekday options but apparently missing something. Believe the error is in the initiation of the event since the daily planner manages to show the options just fine. Please let me know if the issue is in another area so I can display that code to determine what I should be doing differently.

Code: Select all

init:
    $ event("class", "act == 'class'", event.solo(), priority=200)
    $ event("cut1", "act == 'cut'", event.choose_one('cut'), priority=200)
    $ event("cut2", "act == 'cut'", event.choose_one('cut'), priority=200)
    $ event("vocal", "act == 'vocal'", event.solo(), priority=200)
    $ event("tv", "act == 'tv'", event.solo(), priority=200)    
    $ event("sleep", "act == 'sleep'", event.solo(), priority=200)
    $ event("guitar", "act == 'guitar'", event.solo(), priority=200)
    $ event("dance", "act == 'dance'", event.solo(), priority=200)
    $ event("drawing", "act == 'drawing'", event.solo(), priority=200)
    $ event("music", "act == 'music'", event.solo(), priority=200) 
    $ event("exercise", "act == 'exercise'", event.solo(), priority=200)    
    $ event("shop", "act == 'shop'", event.solo(), priority=200)
    $ event("perform", "act == 'perform'", event.solo(), priority=200)
And here's my initiation of periods and events for proper context.

Code: Select all

init python:
    register_stat("Talent", "talent", 5, 100)
    register_stat("Look", "look", 5, 100)
    register_stat("Art", "art", 10, 100)
    register_stat("Mood", "mood", 10, 100)
    register_stat("Mc", "mc", 0, 100)
    register_stat("Karma", "karma", 0, 100)
    register_stat("Wkend", "end", 0, 1)
    
    dp_period("Morning", "morning_act")
    dp_choice("Art Class", "class")
    dp_choice("Cut Class", "cut")
    dp_choice("Vocal Training", "vocal")
    
    dp_period("Morning2", "morning_act")
    dp_choice("Watch Tv", "tv")
    dp_choice("Sleep In", "sleep")
    dp_choice("Play Guitar", "guitar")          
   
    dp_period("Afternoon", "afternoon_act")
    dp_choice("Dance Class", "dance")
    dp_choice("Drawing", "drawing")
    dp_choice("Music Lesson", "music")

    dp_period("Evening", "evening_act")
    dp_choice("Exercise", "exercise")
    dp_choice("Shopping", "shop")
    dp_choice("Perform", "perform")
    
The new options for the weekend are under the "morning2" options. Namely, tv, sleep, & guitar.


Code to tell renpy that it is the weekend:

Code: Select all

if end == 1:
     $ period = "Morning2"
     $ act = morning_act   
    
if end == 0:  
    $ period = "Morning"
    $ act = morning_act

Code: Select all

if end == 1:
     call day_planner(["Morning2", "Afternoon", "Evening"])

if end == 0:  
     call day_planner(["Morning", "Afternoon", "Evening"])
Have tried to change the second set of "morning_act" to "morning2_act" to provide a unique variable, but this didn't allow the event text to display either. Thanks for any help.

lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Re: Converting day numbers into days of the week

#5 Post by lydia »

New to the site and renpy for that matter. Not sure if I'm posting my questions correctly
or if I'm making some other sorts of errors. Could someone suggest some links that
provide more detailed examples of python coding? Haven't had much luck in finding
examples such as how to code for the weekends as in my earlier posting with errors.

If I should be posting such questions in a different manner to make them easier to
follow, please let me know and I will address this issue in my future posts. Thank you.

dc19dc
Regular
Posts: 25
Joined: Mon Sep 02, 2013 1:17 am
Contact:

Re: Converting day numbers into days of the week

#6 Post by dc19dc »

lydia wrote:New to the site and renpy for that matter. Not sure if I'm posting my questions correctly
or if I'm making some other sorts of errors. Could someone suggest some links that
provide more detailed examples of python coding? Haven't had much luck in finding
examples such as how to code for the weekends as in my earlier posting with errors.

If I should be posting such questions in a different manner to make them easier to
follow, please let me know and I will address this issue in my future posts. Thank you.
Hi Lydia, did you ever get the weekend working right? Your code looks like the thing I need to get a weekend working in my game.

gremmie
Newbie
Posts: 2
Joined: Mon Jul 18, 2005 8:05 pm
Contact:

Re: Converting day numbers into days of the week

#7 Post by gremmie »

I can do this. I just did it. I know the thread is old but this is not a bad bit to know.

This is main.rpy of DSE.

Code: Select all

    if todays == "Sunday":
        call screen day_planner(["SunAM", "SunNoon", "SunAft", "SunEve"])
        jump SunAM
    else:
        call screen day_planner(["Morning", "Afternoon", "Houkago", "Evening"])
This bit catches Sundays, which are the only day off.
I found it easier to just do a new screen from scratch for Sundays than otherwise.
That way is more flexible.
Other than that I just recycled the same actions. If you are defining a new default act like 'sleep in' you have to put a label in events.rpy and make a default sleep routine.

NB This is just ripped out of something I am doing - it has an act called 'work' which is not in the DSE and which I have defined in events.rpy like I said. So you can't just dump this into DSE replacing its main, sorry about that. Either delete work act or define work event, up to you.

I had to jump to the special morning and then back at night (night is always the same).

The only thing about recycling acts from the week is if characters have school uniforms they might be wearing them inappropriately when the event kicks off on a Sunday.

Some of the comments in the code got cloned and won't really mean anything.

I hope someone can use this.

Code: Select all

 
# This is the main program. This can be changed quite a bit to
# customize it for your program... But remember what you do, so you
# can integrate with a new version of DSE when it comes out.

# Set up a default schedule.
init python:


    register_stat("Charm", "charm", 10, 100)
    register_stat("Cooking", "cooking", 10, 100)
#    register stat("Creativity", "creativity", 10,100)    
    register_stat("Intelligence", "intelligence", 10, 100)
    register_stat("Strength", "strength", 10, 100)
#    register stat("Fatigue", "fatigue", 10,100)    

    dp_period("Morning", "morning_act")
    dp_choice("Attend Class", "class")
    dp_choice("Cut Class", "cut")
    
    
    
    # This is an example of an event that should only show up under special circumstances
    dp_choice("Fly!", "fly", show="strength >= 100 and intelligence >= 100")

    dp_period("Afternoon", "afternoon_act")
    dp_choice("Study", "study")
    dp_choice("Hang Out", "hang")
    dp_choice("Exercise", "exercise")
    
    dp_period("Houkago", "houkago_act")
    dp_choice("Study", "study")
    dp_choice("Hang Out", "hang")
    dp_choice("Work", "work")
    
    dp_period("Evening", "evening_act")
    dp_choice("Exercise", "exercise")
    dp_choice("Play", "play")
    dp_choice("Work", "work")
 
    dp_period("SunAM", "SunAM_act")
    dp_choice("Study", "study")
    dp_choice("Hang Out", "hang")
    dp_choice("Exercise", "exercise")
 
    dp_period("SunNoon", "SunNoon_act")
    dp_choice("Study", "study")
    dp_choice("Hang Out", "hang")
    dp_choice("Work", "work") 
 
    dp_period("SunAft", "SunAft_act")
    dp_choice("Study", "study")
    dp_choice("Hang Out", "hang")
    dp_choice("Work", "work")
    
    dp_period("SunEve", "SunEve_act")
    dp_choice("Study", "study")
    dp_choice("Hang Out", "hang")
    dp_choice("Exercise", "exercise")
 
# This is the entry point into the game.
label start:

    # Initialize the default values of some of the variables used in
    # the game.
    $ day = 0
    $ daynames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
    # Show a default background.
    scene bg sky

    # The script here is run before any event.
    # Input your name   
    $ your_name = renpy.input("What is my name?", "Yuri", length=20)
    show MainS02
    "I'm [your_name], a girl in the second year of high school."
    show MainS03
    "I spend most of my time looking at girls and daydreaming."
    show MainS05
    "I want to have a girlfriend this year!"
    show MainS06
    "Uh, and I want to get decent grades..."
    scene black with dissolve
    # We jump to day to start the first day.
    jump day


# This is the label that is jumped to at the start of a day.
label day:
    scene bg BedRmDay
    show MainShitagi
    # Increment the day it is.
    $ day += 1

    $ todays =  daynames[(day%7)]
    "It is day [day]. Today is [todays]."
    
    
    # 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.
    
    
    $ SunAM_act = None
    $ SunNoon_act = None
    $ SunAft_act = None
    $ SunEve_act = None
    
    $ morning_act = None
    $ afternoon_act = None
    $ houkago_act = None
    $ evening_act = None
    $ narrator("What should I do today?", interact=False)

    # Now, we call the day planner, which may set the act variables
    # to new values. We call it with a list of periods that we want
    # to compute the values for.
    
    if todays == "Sunday":
        call screen day_planner(["SunAM", "SunNoon", "SunAft", "SunEve"])
        jump SunAM
    else:
        call screen day_planner(["Morning", "Afternoon", "Houkago", "Evening"])

    
    # We process each of the three periods of the day, in turn.
label morning:
    scene black with dissolve

    # Set these variables to appropriate values, so they can be
    # picked up by the expression in the various events defined below. 
    $ period = "morning"
    $ act = morning_act
    
    # Execute the events for the morning.
    call events_run_period

    # That's it for the morning, so we fall through to the
    # afternoon.

label afternoon:
    scene black with dissolve
    # It's possible that we will be skipping the afternoon, if one
    # of the events in the morning jumped to skip_next_period. If
    # so, we should skip the afternoon.
    if check_skip_period():
        jump evening

    # The rest of this is the same as for the morning.

    centered "Afternoon"

    $ period = "afternoon"
    $ act = afternoon_act

    call events_run_period

label houkago:
    scene black with dissolve
    # It's possible that we will be skipping the after school period, if one
    # of the events in the morning jumped to skip_next_period. If
    # so, we should skip the afternoon.
    if check_skip_period():
        jump evening

    # The rest of this is the same as for the morning.

    centered "After School"

    $ period = "houkago"
    $ act = houkago_act

    call events_run_period
    
label evening:
    scene black with dissolve
    # The evening is the same as the afternoon.
    if check_skip_period():
        jump night

    centered "Evening"

    $ period = "evening"
    $ act = evening_act
    
    call events_run_period


label night:
    scene bg BedRmSleep
    # This is now the end of the day, and not a period in which
    # events can be run. We put some boilerplate end-of-day text
    # in here.

    centered "Night"

    "It's getting late, so I decide to go to sleep."
    scene black with dissolve
    # We call events_end_day to let it know that the day is done.
    call events_end_day

    # And we jump back to day to start the next day. This goes
    # on forever, until an event ends the game.
    jump day
         

# This is a callback that is called by the day planner. 
label dp_callback:

    # Add in a line of dialogue asking the question that's on
    # everybody's mind.
    $ narrator("What should I do today?", interact=False)
    
    return

label SunAM:
    scene black with dissolve
    centered "Morning"
    $ period = "SunAM"
    $ act = SunAM_act
    
    # Execute the events for the morning.
    call events_run_period

label SunNoon:
    scene black with dissolve
    centered "Noon"
    if check_skip_period():
        jump evening

    # The rest of this is the same as for the morning.


    $ period = "SunNoon"
    $ act = SunNoon_act

    call events_run_period 

label SunAft:
    scene black with dissolve
    centered "Afternoon"
    if check_skip_period():
        jump evening


    $ period = "SunAft"
    $ act = SunAft_act

    call events_run_period 

label Sun_Eve:
    scene black with dissolve
    # The evening is the same as the afternoon.
    if check_skip_period():
        jump night

    centered "Evening"

    $ period = "SunEve"
    $ act = SunEve_act
    
    call events_run_period
    
    jump night
    

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]