Getting code to mesh?

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
NinaSG
Newbie
Posts: 6
Joined: Fri Aug 27, 2010 3:43 am
Contact:

Getting code to mesh?

#1 Post by NinaSG »

And I'm already back with a question! This does not bode well for my project, though I have gotten a lot more accomplished than I thought I would in such a short amount of time. However, I am having a bit of trouble getting my codes to mesh. I've been writing different pieces into different notepads but for the last few days I've been struggling to get them to coexist. Is there some trick to it that I'm missing? For example....

I have my main page of text, which is just an altered form of the DSE page.

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 theme.
init python:

    register_stat("Charisma", "charisma", 10, 1000)
    register_stat("Strength", "strength", 10, 1000)
    register_stat("Intelligence", "intelligence", 10, 1000)
    register_stat("Stability","stability", 10, 1000)

    dp_period("Morning", "morning_act")
    dp_choice("Attend Class", "class")
    dp_choice("Visit Shopping District", "shop")
    dp_choice("Go To Work", "work")
    dp_choice("Order Groceries", "groceries")
    dp_choice("Stay Home", "home")
    
    dp_period("Afternoon", "afternoon_act")
    dp_choice("Hit The Gym", "gym")
    dp_choice("Visit The Park","park")
    dp_choice("Go To Work","work")
    dp_choice("Visit The Hot Springs","springs")
    dp_choice("Order Groceries", "groceries")
    dp_choice("Stay Home", "home")
    
    dp_period("Evening", "evening_act")
    dp_choice("Go For A Run", "run")
    dp_choice("Visit The Hot Springs","springs")
    dp_choice("Order Groceries", "groceries")
    dp_choice("Stay Home", "home")
    dp_choice("Hang Out", "hang")
    
    dp_period("Night","night_act")
    dp_choice("Visit The Club", "club")
    dp_choice("Visit Late Night Café", "café")
    dp_choice("Study", "study")
    dp_choice("Order Groceries", "groceries")
    dp_choice("Stay Home", "home")
    
     
# 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

    # Show a default background.
    scene black

    # The script here is run before any event.

    "In case you're just tuning in, here's the story of my life to
     date."

    "I'm a guy in the second year of high school."

    "I'm not good at sports or school or even something as simple as
     remembering peoples names."

    "In short, I am your usual random loser guy."

    "And this is my story..."


    # 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:

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

    # We may also want to compute the name for the day here, but
    # right now we don't bother.

    "It's day %(day)d."

    # 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.

    $ morning_act = None
    $ afternoon_act = None
    $ evening_act = None
    $ night_act = None

    # 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.
    call day_planner(["Morning", "Afternoon", "Evening", "Night"])

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

    # Tell the user what period it is.
    centered "Morning"

    # 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

    # Ensure that the stats are in the proper range.
    $ normalize_stats()
    
    # 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:

    # 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

    $ normalize_stats()
    
    call events_run_period


label evening:
    
    # The evening is the same as the afternoon.
    if check_skip_period():
        jump night

    centered "Evening"

    $ period = "evening"
    $ act = evening_act

    $ normalize_stats()
    
    call events_run_period


label night:

    # 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"

    $ period = "Night"
    $ act = night_act

    $ normalize_stats()
    
    call events_run_period


    "It's getting late, so I decide to go to sleep."
    
    # 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. One of the
# uses of this is to show the statistics to the user.
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)
    $ display_stats()

    return

As well as a nifty Calendar I found here on the forums. I'm going to post the semi-original Calendar, since mine is a jumble of days, but the coding itself isn't important, I think I'm just missing some unspoken concept.

Code: Select all

# If you want to add schedules,
# you should change January, Feburary to 13, 14th month
# because for drawing a calendar, January and February is concidered as previous year's 13, 14th month.
# For example, if you want to add date like 2010,2,1 you should write like [2009, 14, 1]

init python:
    week_day = ['sun', 'mon', 'tues', 'wed', 'thur', 'fri', 'sat']              #
    year = 2009                                                           #
    month = 3                                                    #
    day = 2                                                                 # these variables are for your main game progressing. 
   
    schedules = [[2009,3,2,'enter']]
    holiday_list=[ (2009,12,25) ]       # This list is for drawing text to red color. You can add your own holiday list.
                                               
   
###############################################
## For test                                                                       ##
###############################################

label start:
    "I'll ask her..."

    $ ui.vbox(xpos=.5, ypos=.75, xanchor =.5, yanchor=.5)
    $ ui.textbutton('Today is %d. %d. %d. ' %(month, day,year))
    $ ui.textbutton('See Calendar', ui.jumps('initializeForCal'))
    $ ui.textbutton('Add Schedule', ui.jumps('setSchedule'))
    $ ui.close()
    $ ui.interact()

label setSchedule:
   
    # if you want to add a special schedule, use this
    # schedules.append([year,month,day, schedule name that you want to put on calendar])
   
    if not schedules.count([2009,3,4,'date']):
        $ schedules.append([2009,3,4,'date'])
        "Set the schedule"
    else:
        "Schedule is already set"

    jump start

#############################################
## Calendar                                                                      ##
#############################################


label initializeForCal:                 # If you want to show a calendar, your button should call this label.
    python:
        yearForCal = year
        monthForCal = month
        todayWeek = 0

label calendar:

    $ weekDayForCal = ['S',  'M', 'T', 'W', 'T', 'F', 'Sa']
   
    python:
        # Start drawing calendar
        ui.frame(xminimum = 400, yminimum=550, xpos=.5, ypos=.5, xanchor = .5, yanchor=.5)
        ui.vbox()           
        ui.hbox(xpos=.5, ypos=.5, xanchor = .5, yanchor=.5)


        # Drawing date, prev, next button #########
        if (yearForCal==2009 and monthForCal==3):
            ui.textbutton("Prev")         
        else:
            ui.textbutton("Prev", ui.returns(0))

        if monthForCal>12:
            ui.textbutton("%d. %d." %( yearForCal+1, monthForCal-12), xminimum=250)     
        else:
            ui.textbutton("%d. %d." %( yearForCal, monthForCal), xminimum=250)

        if (yearForCal==2011 and monthForCal==14):
            ui.textbutton("Next")
        else:
            ui.textbutton("Next", ui.returns(1))
           
        ui.close()      #for hbox
       
       
        # Drawing the day of weeks ####################
        ui.hbox()
        for weekd in weekDayForCal:
            ui.frame()
            ui.button(xminimum=50)
            if weekd == "S":
                ui.text("{color=#ff0000}"+weekd+"{/size}")
            else:
                ui.text(weekd)
           
        ui.close()      #for hbox
       
        # The variables required for drawing date ############
        num = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,31,28]         
        lastday= num[monthForCal]

        if monthForCal == 2 or monthForCal == 1:                   
            yearForCal-=1
            monthForCal += 12

        th = yearForCal / 100
        yearC = yearForCal % 100
        week = ((21 * th / 4) + (5 * yearC / 4) + (26 * (monthForCal + 1)) / 10) % 7


        # These dates need 6 rows to draw calendar perfectly.
        # So if there is years that you want to use in calendar,
        # you have to check that days with another calendar and add its date here.
        # In here, 2009.5 / 2009.8 / 2010.1 / 2010. 5 / 2010. 10 / 2011.1 / 2011. 7 / 2011. 10
        # needs 6 row
       
        if ((yearForCal==2009 and (monthForCal==5 or monthForCal == 8 or monthForCal ==13))
        or (yearForCal==2010 and (monthForCal==5 or monthForCal==10 or monthForCal == 13))
        or (yearForCal == 2011 and (monthForCal==7 or monthForCal==10))):                             
            r=6
        else:
            r=5

        count = 1

        # Draw Calendar days ####################
       
        for i in range(0, r):
            ui.hbox()
           
            for j in range(0,7):
               
                if i == 0 and j < week:         # Draw null before the first day of the month start
                    ui.frame()
                    ui.null(width=50)
                    todayWeek = i + 1

                else:
                    todayWeek = todayWeek + 1
                    ui.frame()
                    ui.vbox()
                    if yearForCal==year and monthForCal == month and day ==count:
                        normal = RoundRect("#800")              # Mark today in Calendar
                    else:
                        normal = RoundRect("#404040")
                       
                    ui.button(xminimum=50, background = normal)
                    redMark = '#ffffff'                               
                   
                    if todayWeek == 1 :                                # Sunday must be drawn in red
                        redMark = '#ff0000'

                    else:
                        for h_year, h_month, h_day in holiday_list:                                            # Checking holidays and draw that day (text) in red color.
                            if h_year==yearForCal and h_month==monthForCal and h_day==count:
                                redMark = '#ff0000'

                    ui.text("%d" %count, color=redMark)          # Draw day (text) for calendar

                    for y,m,d,s in schedules:       
                        if y==yearForCal and m == monthForCal and d == count:
                            ui.text(s)                                    # Check the added schedule and draw schedule name in bottom of day(text) button

                    ui.close()      # for vbox
                    count+=1

                if count > lastday:
                    ui.close()
                    todayWeek = 1
                    break

            todayWeek = 0         
            ui.close()
       
        ui.textbutton('return', ui.jumps('start'))
        next = ui.interact()
       
        if next:
            if monthForCal >11 and not (monthForCal >=13) :
                monthForCal = 1
                yearForCal+=1
               
            elif monthForCal==14:
                monthForCal = 3

                yearForCal+=1
            else:
                monthForCal +=1

        else:
            monthForCal-=1


    call calendar

Now, what I'm trying to do it make it so that 1) there's a button on the call_back page that allows me to see the Calendar itself. Also, instead of saying "It's day 1," it should say "It's Month, Day." I can get the scripts (meaning, the call_back page), the calendar, and my "What day is it" bit to run by themselves but when I try to put them in a single code so they work together only one will play (the call_back page and the original "It's day 1" statement obliterates everything else).

I don't get an error or anything, it just doesn't work. Any ideas where I'm going wrong?

Cironian
Regular
Posts: 33
Joined: Sun Aug 26, 2007 5:34 pm
Projects: Dragon Story
Contact:

Re: Getting code to mesh?

#2 Post by Cironian »

For anyone to help you, it would be useful to see how exactly you tried to combine the two code snippets. Did you just paste them after each other (which most definitely wouldn't work, with two "label start" blocks) or did you already try combining the code blocks in some fashion?

NinaSG
Newbie
Posts: 6
Joined: Fri Aug 27, 2010 3:43 am
Contact:

Re: Getting code to mesh?

#3 Post by NinaSG »

Oh, sorry. That...makes sense. Anyway, here's the code. It's completely ignoring the week days I put in, meaning instead of saying "Today is Monday." it just says "Today is 1."

In addition, it doesn't show the callback screen (the one with the stats and event options) at all. It just shows the button for the calendar at the bottom.

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 theme.
init python:

    register_stat("Charisma", "charisma", 10, 1000)
    register_stat("Strength", "strength", 10, 1000)
    register_stat("Intelligence", "intelligence", 10, 1000)
    register_stat("Stability","stability", 10, 1000)

    dp_period("Morning", "morning_act")
    dp_choice("Attend Class", "class")
    dp_choice("Visit Shopping District", "shop")
    dp_choice("Go To Work", "work")
    dp_choice("Order Groceries", "groceries")
    dp_choice("Stay Home", "home")
    
    dp_period("Afternoon", "afternoon_act")
    dp_choice("Hit The Gym", "gym")
    dp_choice("Visit The Park","park")
    dp_choice("Go To Work","work")
    dp_choice("Visit The Hot Springs","springs")
    dp_choice("Order Groceries", "groceries")
    dp_choice("Stay Home", "home")
    
    dp_period("Evening", "evening_act")
    dp_choice("Go For A Run", "run")
    dp_choice("Visit The Hot Springs","springs")
    dp_choice("Order Groceries", "groceries")
    dp_choice("Stay Home", "home")
    dp_choice("Hang Out", "hang")
    
    dp_period("Night","night_act")
    dp_choice("Visit The Club", "club")
    dp_choice("Visit Late Night Café", "café")
    dp_choice("Study", "study")
    dp_choice("Order Groceries", "groceries")
    dp_choice("Stay Home", "home")
    
    week_day = ['sun', 'mon', 'tues', 'wed', 'thur', 'fri', 'sat']              #
    year = 2009                                                           #
    month = 3                                                    #
    day = 2                                                                 # these variables are for your main game progressing. 
   
    schedules = [[2009,3,2,'enter']]
    holiday_list=[ (2009,12,25) ]       # This list is for drawing text to red color. You can add your own holiday list.    
    
# 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

    # Show a default background.
    scene black

    # The script here is run before any event.

    "And this is my story..."


    # 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:

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

    # We may also want to compute the name for the day here, but
    # right now we don't bother.

    "Today is %(day)d."

    # 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.

    $ morning_act = None
    $ afternoon_act = None
    $ evening_act = None
    $ night_act = None

    $ ui.vbox(xpos=1190, ypos=725, xanchor =1.0, yanchor=.5)
    $ ui.textbutton('Today is %d. %d. %d. ' %(month, day,year))
    $ ui.textbutton('See Calendar', ui.jumps('initializeForCal'))
    $ ui.textbutton('Add Schedule', ui.jumps('setSchedule'))
    $ ui.close()
    $ ui.interact()
        
    # 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.
    call day_planner(["Morning", "Afternoon", "Evening", "Night"])

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

    # Tell the user what period it is.
    centered "Morning"

    # 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

    # Ensure that the stats are in the proper range.
    $ normalize_stats()
    
    # 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:

    # 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

    $ normalize_stats()
    
    call events_run_period


label evening:
    
    # The evening is the same as the afternoon.
    if check_skip_period():
        jump night

    centered "Evening"

    $ period = "evening"
    $ act = evening_act

    $ normalize_stats()
    
    call events_run_period


label night:

    # 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"

    $ period = "Night"
    $ act = night_act

    $ normalize_stats()
    
    call events_run_period


    "It's getting late, so I decide to go to sleep."
    
    # 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. One of the
# uses of this is to show the statistics to the user.
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)
    $ display_stats()

    return

User avatar
Gryphbear
Regular
Posts: 91
Joined: Wed Jun 16, 2010 11:45 pm
Contact:

Re: Getting code to mesh?

#4 Post by Gryphbear »

Might have to set the 'day' variable to equal the string of the "Day"?

I don't know the exact code, but it looks like you are trying to display the numerical value of the "Day" rather than the Day's name.

I could be wrong.
WIP: Ring av Guder - (Contemporary Fantasy VN/Dating Sim?)

What do you get when you inherit a mystical ring, meet Norse Dieties, and Werewolves, Satyrs, or Dwarves? Possibilities.

General Completion: 5% - (Still working on story plot.)
Story status: 1% (In progress of revamping)
Scripting: 1% (Prologue is about done)
Character Art: 0% (Would like to find a Bara-type Artist, but will learn to draw them myself if necessary)
BG/CG's: 0% (None so far)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Ocelot