[SOLVED] Issue with unlockable character profiles

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
gummii_exe
Newbie
Posts: 13
Joined: Fri Jun 10, 2022 11:42 am
Contact:

[SOLVED] Issue with unlockable character profiles

#1 Post by gummii_exe »

In my game I'm working on a system to have a screen for character profiles, which unlock as you meet them. I have a character class defined as follows;

Code: Select all

init python:
    import renpy.store as store
    import renpy.exports as renpy

    class Chara(store.object):
        def __init__(self, name, pronouns, description, meet = False):
         #imageName = "",
            self.name = name
            self.pronouns = pronouns
            self.description = description
            #self.imageName = "characters/"+ imageName + ".png"
            self.meet = meet
then, following a tutorial, I made a second class as a character list, to show which characters have already been met (this is within the same init python block)

Code: Select all

 class CharaList(store.object):
        def __init__(self):
            self.chara_list = []

        def metChara(self, chara):
            self.chara_list.append(chara)

        def removeChara(self, chara):
            self.chara_list.remove(chara)

        def hasChara(self, chara):
            if chara in self.chara_list:
                return True
            else:
                return False
I added the hasChara function so that I could hopefully set a conditional within my character screen to only show a text button if the character the button was for was in the CharaList, but whenever I run my game and try to open the character screen I get an error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "game/characters_screen.rpy", line 10, in execute
    screen CharactersUI:
  File "game/characters_screen.rpy", line 10, in execute
    screen CharactersUI:
  File "game/characters_screen.rpy", line 13, in execute
    hbox:
  File "game/characters_screen.rpy", line 14, in execute
    frame:
  File "game/characters_screen.rpy", line 18, in execute
    vbox:
  File "game/characters_screen.rpy", line 24, in execute
    if CharaList.hasChara(Bug):
  File "game/characters_screen.rpy", line 24, in <module>
    if CharaList.hasChara(Bug):
TypeError: unbound method hasChara() must be called with CharaList instance as first argument (got Chara instance instead)
For clarity, my character screen looks like this

Code: Select all

screen charactersButton:
    textbutton _("characters"):
        xalign 1.0
        yalign 0.0
        xoffset -30
        yoffset 30
        action ShowMenu("CharactersUI")
#character screen goes here
screen CharactersUI:
    tag charactersUI
    add "UI/moon.png"
    hbox:
        frame:
            style_prefix "characters"
            ysize 1080
            xsize 640
            vbox:
                xalign 0.5
                yalign 0.5
                textbutton _(Player.name):
                    action SetVariable("selectedCharacter", Player)
                    xsize 640
                if CharaList.hasChara(Bug):
                    textbutton _(Bug.name):
                        action SetVariable("selectedCharacter", Bug)
                        xsize 640

            textbutton _("Return"):
                yalign 0.5
                yoffset 90
                xoffset 20
                action Return()
        ## Right frame
        ## Notice that we're using selectedCharacter to show the variables here.
        frame:
            ysize 1080
            xsize 1280
            vbox:
                xoffset 20
                yoffset 20
                text "Name: [selectedCharacter.name]"
                text "Pronouns: [selectedCharacter.pronouns]"
                text "Description: [selectedCharacter.description]" 
If any other code is needed, please let me know! I've tried a lot of different wording to try and fix the issue but at this point I'm clueless..
Last edited by gummii_exe on Sun Jun 12, 2022 11:46 am, edited 2 times in total.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Issue with unlockable character profiles

#2 Post by _ticlock_ »

Hi, gummii_exe,

It is questionable if you really need class CharaList. Anyway, the error you have is because CharaList is a class and not a variable. If you want to use this class, you need to create an instance first:

Code: Select all

$ CList = CharaList()

Code: Select all

if Clist.hasChara(Bug):
  # Something to do

gummii_exe
Newbie
Posts: 13
Joined: Fri Jun 10, 2022 11:42 am
Contact:

Re: Issue with unlockable character profiles

#3 Post by gummii_exe »

Thank you so much- The tutorial I followed did have you define a variable like that, but it was never explained that it needed to be used like that.. That clears it up perfectly. :)

Post Reply

Who is online

Users browsing this forum: Directony