Ren'Py QuickStart [Gallery, Codex, Scheduler, Tutorials etc]

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.
Message
Author
User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Ren'Py QuickStart [Gallery, Codex, Scheduler, Tutorials

#91 Post by noeinan »

Hm, so I know that you can't just delete the codex and inventory files, because other code references them. However, just to see if I could get to where you're at, I did try simply deleting them and I didn't get any error messages unless I tried to click buttons that specifically referenced the inventory or codex.

Is it possible that you made some other changes to the code besides this? The code shouldn't ever try to reference "None" as a label-- that is just a value that is entered by default to make sure the player can't go through the schedule without picking an activity. If you look at the month label, you can see I have set "None" as the default value for each week.

Code: Select all

label month:
   
    $ month_cnt += 1
   
    scene bg default
   
    #Setting default values for the schedule
   
    $ week01 = None
    $ week02 = None
    $ week03 = None
    $ week04 = None
    $ show_date = False
Then below that, I have a label called "schedule_repeat" which checks to see if any of the values are still set to "None"-- to make sure the player has actually selected an activity-- and then if they are it displays a helpful error message telling the player they have to pick an activity. As you can see, it's also set up to be a loop, so the player cannot leave this loop without every single week having a value other than "None."

Code: Select all

label schedule_repeat:

    call screen schedule

    if week01 is None or week02 is None or week03 is None or week04 is None:

        "Please pick an activity for every week this month."

        jump schedule_repeat
If your game is looking for a "None" label, to me that means something must have happened to this code. Somehow, you are getting through this loop while keeping the "None" label-- and then when later code has you jump to whatever the value of that week is, you get an error because I haven't set up any activities or labels for "None". (I probably should go back at some point and add an error message in the event that this somehow happens.)

In any case, I would check to make sure that the schedule_repeat label is still there, and is in the correct location. It should be right after the month label.

I also tested the base code, without removing anything, to check to see if maybe a Ren'Py update made some changes-- but it worked fine. I went ahead and removed the codex and inventory completely on my end, making sure the code still worked. These are the parts you have to remove in order to keep it working:

In the script.rpy file, remove this entire section of code:

Code: Select all

init python:
    
    class Player(renpy.store.object):
        def __init__(self, name, max_hp=0, max_mp=0, element=None):
            self.name=name
            self.max_hp=max_hp
            self.hp=max_hp
            self.max_mp=max_mp
            self.mp=max_mp
            self.element=element
    player = Player("Derp", 100, 50)
    
    class Item(store.object):
        def __init__(self, name, player=None, hp=0, mp=0, element="", image="", cost=0):
            self.name = name
            self.player=player # which character can use this item?
            self.hp = hp # does this item restore hp?
            self.mp = mp # does this item restore mp?
            self.element=element # does this item change elemental damage?
            self.image=image # image file to use for this item
            self.cost=cost # how much does it cost in shops?
        def use(self): #here we define what should happen when we use the item
            if self.hp>0: #healing item
                player.hp = player.hp+self.hp
                if player.hp > player.max_hp: # can't heal beyond max HP
                    player.hp = player.max_hp
                inventory.drop(self) # consumable item - drop after use
            elif self.mp>0: #mp restore item
                player.mp = player.mp+self.mp
                if player.mp > player.max_mp: # can't increase MP beyond max MP
                    player.mp = player.max_mp
                inventory.drop(self) # consumable item - drop after use
            else:
                player.element=self.element #item to change elemental damage; we don't drop it, since it's not a consumable item
    
    class Inventory(store.object):
        def __init__(self, money=10):
            self.money = money
            self.items = []
        def add(self, item): # a simple method that adds an item; we could also add conditions here (like check if there is space in the inventory)
            self.items.append(item)
        def drop(self, item):
            self.items.remove(item)
        def buy(self, item):
            if self.money >= item.cost:
                self.items.append(item)
                self.money -= item.cost
    
    player = Player("Derp", 100, 50)
    player.hp = 50
    player.mp = 10
    chocolate = Item("Chocolate", hp=40, image="gui/inv_chocolate.png")
    banana = Item("Banana", mp=20, image="gui/inv_banana.png")    
    gun = Item("Gun", element="bullets", image="gui/inv_gun.png", cost=7)
    laser = Item("Laser Gun", element="laser", image="gui/inv_laser.png")
    inventory = Inventory()
    #add items to the initial inventory:
    inventory.add(chocolate)
    inventory.add(chocolate)
    inventory.add(chocolate)
    inventory.add(chocolate)
    inventory.add(banana)
    inventory.add(banana)
    inventory.add(banana)
    inventory.add(banana)
    inventory.add(gun)
    inventory.add(laser)
In the screens.rpy file, remove the sections marked in bold:

Code: Select all

##############################################################################
# Main Menu 
#
# Screen that's used to display the main menu, when Ren'Py first starts
# http://www.renpy.org/doc/html/screen_special.html#main-menu

screen main_menu:

    # This ensures that any other menu screen is replaced.
    tag menu

    # The background of the main menu.
    window:
        style "mm_root"

    # The main menu buttons.
    frame:
        style_group "mm"
        xalign .98
        yalign .98

        has vbox

        textbutton _("Start Game") action Start()
[b]        textbutton _("Codex") action ShowMenu("codex")[/b]
        textbutton _("CG Gallery") action ShowMenu("cg_gallery")
        textbutton _("BG Gallery") action ShowMenu("bg_gallery")
        textbutton _("Load Game") action ShowMenu("load")
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit(confirm=False)

init -2 python:

    # Make all the main menu buttons be the same size.
    style.mm_button.size_group = "mm"

Code: Select all

##############################################################################
# Game Menu
#
# Screen that appears when the player presses the escape button.

image logo = "logo.jpg"

screen game_menu:
    tag menu
    
    add "logo"
    
    frame: 
        xalign .5
        yalign .33
        
        has vbox spacing 5
   
        textbutton _("Continue") action Return()
        textbutton _("Save Game") action ShowMenu("save")
        textbutton _("Load Game") action ShowMenu("load")
[b]        textbutton _("Codex") action ShowMenu("codex")[/b]
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Main Menu") action MainMenu()
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit()
In home.rpy, you need to change the bold section-- *do not just delete it, because this is a grid. We've already determined that the grid is 4 across and 2 down, so if you just delete it you will get an error. (Likely that grid error you were mentioning before.) What I did is change it from "textbutton "Items" action Show("inventory_screen")" to "textbutton "Items" action Show("blank")" but you can add a different button that fits your game.

Code: Select all

screen home:
    tag menu2
    
    frame:
        style_group "home"
        xalign 1.0
        yalign 0.8
        
        grid 4 2:
            transpose False
            textbutton "Stats" action Show("stats")
            textbutton "Talk" action Show("talk")
            textbutton "Diet" action Show("diet")
            textbutton "Info" action Show("info")
            
            textbutton "Town" action Show("town")
            textbutton "Castle" action Show("castle")
[b]            textbutton "Items" action Show("inventory_screen")[/b]
            textbutton "Save" action ShowMenu("save")
    
    frame:
        style_group "home2"
        xalign 1.0
        yalign 1.0
        vbox: 
            textbutton "Schedule" action Jump("month")
            
init python:
    #This controls minimum button length
    style.home = Style(style.frame)
    style.home_button.xmaximum = 100
    style.home_button.xminimum = 100
    style.home_button.yminimum = 100
    style.home_button.ymaximum = 100
    
init python:
    #This controls minimum button length
    style.home2 = Style(style.frame)
    style.home2_button.xmaximum = 400
    style.home2_button.xminimum = 400
    style.home2_button.yminimum = 100
    style.home2_button.ymaximum = 100
Also in home.rpy, remove this entire section:

Code: Select all

#ITEMS

screen items:
    
    tag menu
    
    frame:
        style_group "items"
        xalign 0.3
        yalign 0.3
        
        vbox:
            textbutton "Remove Weapon"
            textbutton "Remove Armor"
            
            textbutton "Cancel" action Hide("menu") 
            
init python:
    #This controls minimum button length
    style.items_button.xminimum = 20
    style.items_label.xalign = .5
However, you need to replace it with your new button. Since I am just leaving a blank button, all I did was copy the "castle" button and change the name to "blank"-- that way the blank button has something to do and doesn't end in an error. Here's what I ended up with:

Code: Select all

#BLANK

screen blank:
    
    tag menu
    
    frame:
        style_group "blank"
        xalign 0.3
        yalign 0.3
        
        vbox:
            textbutton "Palace Guard"
            textbutton "Royal Knight"
            textbutton "General"
            textbutton "Minister of State"
            textbutton "Archbishop"
            textbutton "Royal Concubine"
            textbutton "Queen"
            textbutton "King"
            textbutton "Jester"
            
            textbutton "Cancel" action Hide("menu") 
            
init python:
    #This controls minimum button length
    style.castle_button.xminimum = 220
    style.castle_label.xalign = .5
If you do that, it should work with no errors. (Or at least it is working for me.) If you are still having problems after that, let me know and I can just zip up what I have and send it to you.
Image

Image
Image

User avatar
Pomeranian
Regular
Posts: 33
Joined: Wed Oct 12, 2016 6:52 pm
Contact:

Re: Ren'Py QuickStart [Gallery, Codex, Scheduler, Tutorials

#92 Post by Pomeranian »

Hi there, I've been fiddling around with the code a bit, and I've run into an issue.

So I've been trying to create a birthday event, but for whatever reason it's not working. (probably an error on my part) Renpy hasn't displayed an error so I'm guessing it isn't a syntax error but rather something to do with the variables themselves.

In order to set the birthday, I created two variables - BRTHMNTH for the month and BRTHDTE for the day.

I put this at the beginning of the game (before the home menu)

Code: Select all

    menu:
        "January":
            $ BRTHMNTH = 'January'
        "February":
            $ BRTHMNTH = 'February'
        "March":
            $ BRTHMNTH = 'March'
        "April":
            $ BRTHMNTH = 'April'
        "May":
            $ BRTHMNTH = 'May'
        "June":
            $ BRTHMNTH = 'June'
        "July":
            $ BRTHMNTH = 'July'
        "August":
            $ BRTHMNTH = 'August'
        "September":
            $ BRTHMNTH = 'September'
        "October":
            $ BRTHMNTH = 'October'
        "November":
            $ BRTHMNTH = 'November'
        "December":
            $ BRTHMNTH = 'December'
I made a similar menu with the birthdate, but I used integers to set the variable, rather than a string. (I tried it both ways, with and without the commas, and neither worked)

Under label check_events I put:

Code: Select all

    if calendar.month == BRTHMNTH and calendar.day == BRTHDTE:
        $ AGENUM += 1
        jump Daughter_birthday
and I created a Daughter_birthday event as well, but it's not showing up no matter what date I've put. I'd also note that the harvest festival event isn't working for me either.

If anyone can explain what I've done wrong, I'd really appreciate it!

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Ren'Py QuickStart [Gallery, Codex, Scheduler, Tutorials

#93 Post by noeinan »

Pomeranian wrote:Hi there, I've been fiddling around with the code a bit, and I've run into an issue.

So I've been trying to create a birthday event, but for whatever reason it's not working. (probably an error on my part) Renpy hasn't displayed an error so I'm guessing it isn't a syntax error but rather something to do with the variables themselves.

In order to set the birthday, I created two variables - BRTHMNTH for the month and BRTHDTE for the day.

I put this at the beginning of the game (before the home menu)

Code: Select all

    menu:
        "January":
            $ BRTHMNTH = 'January'
        "February":
            $ BRTHMNTH = 'February'
        "March":
            $ BRTHMNTH = 'March'
        "April":
            $ BRTHMNTH = 'April'
        "May":
            $ BRTHMNTH = 'May'
        "June":
            $ BRTHMNTH = 'June'
        "July":
            $ BRTHMNTH = 'July'
        "August":
            $ BRTHMNTH = 'August'
        "September":
            $ BRTHMNTH = 'September'
        "October":
            $ BRTHMNTH = 'October'
        "November":
            $ BRTHMNTH = 'November'
        "December":
            $ BRTHMNTH = 'December'
I made a similar menu with the birthdate, but I used integers to set the variable, rather than a string. (I tried it both ways, with and without the commas, and neither worked)

Under label check_events I put:

Code: Select all

    if calendar.month == BRTHMNTH and calendar.day == BRTHDTE:
        $ AGENUM += 1
        jump Daughter_birthday
and I created a Daughter_birthday event as well, but it's not showing up no matter what date I've put. I'd also note that the harvest festival event isn't working for me either.

If anyone can explain what I've done wrong, I'd really appreciate it!

Hey, I'm sorry for the late reply. My health has been particularly bad and I haven't been able to check the forums as often as I used to.

Regarding your code, I'm not 100% sure without actually having your file but from looking at what you pasted here are my thoughts.

Code: Select all

menu:
        "January":
            $ BRTHMNTH = 'January'
In my code, when I set variables I don't use quotations. It's possible that the quotation marks are preventing your code from properly meshing with the calendar. For example, here is a piece of my code:

Code: Select all

label month:
   
    $ month_cnt += 1
   
    scene bg default
   
    #Setting default values for the schedule
   
    $ week01 = None
    $ week02 = None
    $ week03 = None
    $ week04 = None
    $ show_date = False
Here, I set the value of each week as None, not 'None'. The calendar code stores each month as January, not 'January' so that might be your problem. (But I haven't been able to code in quite a while, so I may be rusty on the technicalities of the script. I usually have to refresh myself whenever I get back into it after a while away.)

Regarding the harvest festival, that one is actually a bug. I made a mistake when coding, thanks for reporting! I've fixed it and am posting a repaired version now. Will also upload the pinned post with the new file. Here is how to fix it in your file, so you don't have to download the whole thing:

1. In the script.rpy file, find this code block. Should start at line 159.

Code: Select all

label check_events:
    
    if current_week != "None":
        $ renpy.jump(current_week + "_evt")
    
    if calendar.month == "September" and calendar.day == 30:
        jump Harvest_Festival
    
    #if calendar.moonphase == "full moon":
        #$ insanity += 5
        
    return
Now, change it to this:

Code: Select all

label check_events:
    
    if current_week != "None":
        $ renpy.jump(current_week + "_evt")
    
    return
    
label check_daily:
    
    #if calendar.moonphase == "full moon":
        #$ insanity += 5

    if calendar.month == "September" and calendar.day == 30:
        jump Harvest_Festival
        
    return
2. Open the week.rpy file. You will see all my default events look like this:

Code: Select all

label Art:
    
    $ calendar.next() #This will causes the calendar to advance by one day
    show screen calendar #Shows the date in the top right corner of the screen
    
    if current_day == 1: #This intro only shows on the first day of the week
        "You go to the forest in the back of the school to draw."
    
    [b]call check_events #check to see if any events have been triggered.[/b]
    
    if current_day < 7 and not calendar.last_day_of_the_month:
        $ current_day += 1
        jump Art
    
    hide screen calendar
    
    return
You need to call "check_daily" BEFORE "check_events". You can just change it to this:

Code: Select all

label Art:
    
    $ calendar.next() #This will causes the calendar to advance by one day
    show screen calendar #Shows the date in the top right corner of the screen
    
    if current_day == 1: #This intro only shows on the first day of the week
        "You go to the forest in the back of the school to draw."
    
    call check_daily #check to see if any date based events have been triggered.
    call check_events #check to see if any events have been triggered.
    
    if current_day < 7 and not calendar.last_day_of_the_month:
        $ current_day += 1
        jump Art
    
    hide screen calendar
    
    return
Do that for every event in the file. The problem was, before I just had one event checker. What would happen is, since the check for current_week came before the calendar check, the code would always just start the event checker and then jump to the week's activity again instead of continuing on to see what date it was. I fixed this by adding a new event checker which gets checked every day instead of every week. (The week event checker is needed to make sure you go to the correct activity.)

With this code, all events will only trigger *after* you have gone through the day's chosen activity. (School, work, etc.) If you wanted the events to be triggered *before*, you could probably just move the calendar checker above the week checker. This would also trigger events at the start of the week, before you hit the home screen. Up to personal preference really. If you wanted to do it this way, you would leave events.rpy alone and just change script.rpy to this:

Code: Select all

label check_events:
    
    #if calendar.moonphase == "full moon":
        #$ insanity += 5

    if calendar.month == "September" and calendar.day == 30:
        jump Harvest_Festival

    if current_week != "None":
        $ renpy.jump(current_week + "_evt")
        
    return
That will always prioritize daily events over school. So if you fill out your planner, and click to play through the week, it might launch you right into a date based event. You can combine these two methods in order to have some "before school/work/etc." events and some "after school/work/etc." events. There are some rules you need to follow to make that work.

1. If you have any "events" that don't jump to a label, but instead change the MC's stats (such as the moon phase thing) they need to show up FIRST. This applies to either the check_events or the check_daily. If you put these last, then if any other event listed before them in the code is triggered, those stats will not be applied. The code will exclude the stat modification all together, only getting a chance to get it again the next time you go through the loop.

2. All before-school events must be placed in the check_events label, *before* the current_week check. Otherwise it will just jump to the week's activity and skip it.

3. Before school events will need to be programmed differently than other events. IF you want to be able to do the event, and then allow the player to go to school after, you need to exclude the code that switches you to the next day. In addition, you do NOT need to add check_events, because the script will return

In addition, instead you should use check_events NOT check_daily. Otherwise you risk triggering more than one daily event after another. If this is okay, you could put check_daily first and then check_events after. This will put you in a loop of daily events, and once you run out of daily events it will proceed to the regular weekly event. Here is what the Art event would look like if I were to format it like a before-school event:

Code: Select all

label Art:
    
    show screen calendar #Shows the date in the top right corner of the screen
    
    "Art is happening before school! So fun."

    call check_daily #check to see if any other daily events are triggered. 
    
    hide screen calendar
    
    return
Attachments
16.12.08-quick-start Renpy Framework.zip
(7.34 MiB) Downloaded 155 times
Image

Image
Image

User avatar
Pomeranian
Regular
Posts: 33
Joined: Wed Oct 12, 2016 6:52 pm
Contact:

Re: Ren'Py QuickStart [Gallery, Codex, Scheduler, Tutorials

#94 Post by Pomeranian »

Thank you for the reply! Thanks to your updated code, I've gotten almost everything working how I want it to with regards to the harvest festival and other events, but I'm still a little confused on getting the birthday and calendar date to work properly together.
In my code, when I set variables I don't use quotations. It's possible that the quotation marks are preventing your code from properly meshing with the calendar.
I was basing my birthday event code on this part of your code, so I'm not sure why it wouldn't recognize the quotations around the month names.

Code: Select all

    if calendar.month == "September" and calendar.day == 30:
        jump Harvest_Festival
I believe it may have something to do with not returning + comparing the calendar.month_names to my code properly? I'm unsure how to go about getting that to work, though.

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Ren'Py QuickStart [Gallery, Codex, Scheduler, Tutorials

#95 Post by noeinan »

Ey, so photobucket just removed 3rd party hosting and that removed all the images for this thread. I'm fixing up the ones in the main post but may not get to all the comments.
Image

Image
Image

User avatar
parttimestorier
Veteran
Posts: 429
Joined: Thu Feb 09, 2017 10:29 pm
Completed: No Other Medicine, Well Met By Moonlight, RE:BURN, The Light at the End of the Ocean, Take A Hike!, Wizard School Woes
Projects: Seeds of Dreams
itch: janetitor
Location: Canada
Contact:

Re: Ren'Py QuickStart [Gallery, Codex, Scheduler, Tutorials etc]

#96 Post by parttimestorier »

Thanks so much for this code and the great tutorial! I was looking for a way to set up schedule mechanics that was a bit less complicated than the DSE and this was exactly what I needed. I have a very nice simple schedule set up now thanks to the tutorial being so easy to follow!
ImageImageImage

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Ren'Py QuickStart [Gallery, Codex, Scheduler, Tutorials etc]

#97 Post by noeinan »

I'm really glad that you found it helpful! If I have time, I'll go over and update things to make it more polished, I'm glad folks are still getting some use out of this.
Image

Image
Image

Post Reply

Who is online

Users browsing this forum: No registered users