[SOLVED] How to get a variable from a python object to a renpy.say() statement

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
Chekhov
Regular
Posts: 113
Joined: Tue Jun 26, 2018 9:19 am
Projects: Pluton
Contact:

[SOLVED] How to get a variable from a python object to a renpy.say() statement

#1 Post by Chekhov »

I'm trying to test some objects and object functions for use in Ren'Py

This is how a class is created:

Code: Select all

init python:
	class Emotion(object):
        	def __init__(self, name="Emotion_naming_error", start = 0):
            		self.name = name
            		self.value = start

        	def get(self):
            		return self.value
Creation of the object:

Code: Select all

anger = Emotion("anger")
And trying to get the current value in either method:

Code: Select all

"anger = [anger.get]"
$ renpy.say(None, "angersay = [anger.get]")
Both display a "<bound Emotion.get of <store.Emotion> object at 0x03BA2A30>>" (not an error).
I would have expected the value 0.

How do I get a variable from an object to return to renpy.say() ?
Last edited by Chekhov on Wed Jul 11, 2018 9:44 am, edited 1 time in total.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How to get a variable from a python object to a renpy.say() statement

#2 Post by trooper6 »

May I ask why you are using renpy.say and not just having your character or narrater just say whatever?

Also, in Python (which Renpy is based on), it isn't Pythonic to have getters and setters, just access the variable directly.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Chekhov
Regular
Posts: 113
Joined: Tue Jun 26, 2018 9:19 am
Projects: Pluton
Contact:

Re: How to get a variable from a python object to a renpy.say() statement

#3 Post by Chekhov »

trooper6 wrote: Tue Jul 10, 2018 6:45 pm May I ask why you are using renpy.say and not just having your character or narrater just say whatever?
I am an inexperienced coder and I wasn't sure if it would make a difference, so I tried either to test it out.
Also, in Python (which Renpy is based on), it isn't Pythonic to have getters and setters, just access the variable directly.
Thanks just using anger.value directly works. Not sure what I was thinking, but that solved it. Thank you!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot