[Solved] Default class not updating for defined value

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
User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

[Solved] Default class not updating for defined value

#1 Post by HB38 »

I can't believe I am having issues here since my whole project is about 100 words, but I'm defining a class as follows in one file:

Code: Select all

init -2 python:
    class char() :
         def __init__ (self, firstName, lastName, fullName, age):
            self.firstName = "First Name"
            self.lastName = "Last Name"
            self.fullName = "Full Name"
            self.age = 18
And then in another file I'm defining a test character:

Code: Select all

define test_char = char("Test","Character","Test Character", 25)
However, when I status this character's info in play it's showing the defaults instead of their newly defined traits. Here is the actual script:

Code: Select all

label start:
    "test_char" "Hi, my name is [test_char.fullName].  I am [test_char.age] years old."
This outputs the default values (Full Name and 18 respectively) instead of the defined values (Test Character and 25). If I modify the values ahead of time (with a simple $ test_char.fullName = "Test Character" it will show the correct thing, so it looks like it will update correctly but I can't get it to start with the proper defaults.

I also tried using default instead of define and it had no change, but I want to use default here for sure (I just used define here for clarity in explaining the issue). The only thing I can think of is that I'm using Ren'py 8.0.0?
Last edited by HB38 on Sun Jun 12, 2022 5:09 pm, edited 3 times in total.

User avatar
Syrale
Regular
Posts: 101
Joined: Sun Oct 25, 2015 10:28 am
Completed: Robot Daycare, Deep Sea Valentine, Locke(d)
Projects: Artificial Selection, Artificial Fashionista, rei_carnation
Github: kigyo
itch: kigyo
Discord: kigyodev
Contact:

Re: Default class not updating for defined value

#2 Post by Syrale »

Currently, your values are set to "First Name", etc. instead of what you pass on to the constructor.
The correct way to do it would be:

Code: Select all

class char() :
    def __init__ (self, firstName="First Name", lastName="Last Name", fullName="Full Name", age=18):
        self.firstName = firstName
        self.lastName = lastName
        self.fullName = fullName
        self.age = age
ImageArtificial Selection (ongoing) |ImageDeep Sea Valentine | ImageRobot Daycare (NaNo19)
| ImageArtificial Fashionista (NaNo24)

My Developer Tools: Ren'Py Minimap/Location System | Ren'Py Word Counter+

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: Default class not updating for defined value

#3 Post by HB38 »

Syrale wrote: Sun Jun 12, 2022 2:10 pm Currently, your values are set to "First Name", etc. instead of what you pass on to the constructor.
The correct way to do it would be:

Code: Select all

class char() :
    def __init__ (self, firstName="First Name", lastName="Last Name", fullName="Full Name", age=18):
        self.firstName = firstName
        self.lastName = lastName
        self.fullName = fullName
        self.age = age
That was stupid easy, not sure what I saw in other threads but oh well. Thanks!

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: [Solved] Default class not updating for defined value

#4 Post by HB38 »

Related; is there an easy way to adjust the class so that it's more clear/easy to read (I'm trying to make an easy to read template). I see someone mentioned something similar to what I was looking for here; ideally I'd like to swap from:

Code: Select all

define test_char = char("Test","Character","Test Character", 24)
to

Code: Select all

define test_char = char(
   firstName = "Test",
   lastName = "Character",
   fullName = "Test Character",
   age = 24,
   )
However, when I do so I get an error suggesting I should be using '=='. Updating to that throws a syntax error that firstName is not defined.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Default class not updating for defined value

#5 Post by zmook »

Have you copied something incorrectly? this works fine for me.

Code: Select all

init python:
    class char() :
        def __init__ (self, firstName="First Name", lastName="Last Name", fullName="Full Name", age=18):
            self.firstName = firstName
            self.lastName = lastName
            self.fullName = fullName
            self.age = age
            
define test_char = char(
   firstName = "Test",
   lastName = "Character",
   fullName = "Test Character",
   age = 24,
   )
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: Default class not updating for defined value

#6 Post by HB38 »

Yeah, it's working for me now. Part of my issue was something I've never noticed before: If I flag a value and follow it with a say statement, it doesn't seem to show up in the variable viewer until the next say statement. Weird, but working as intended now. Thanks for the sanity check!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], LuckyT