[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
Newbie
Posts: 14
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 » Tue Jul 10, 2018 6:09 pm

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: 3265
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 » 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?

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 (Jul 10): Converted LiveComposite Sprites to LayeredImages
*Currently Doing: Trying to work out the transition thing for two character using the same sprite and try to figure out how to redo my multi-barber thing...i.e. see if there is a way to re_do my character callbacks
*First Next thing to do: Rebuild the project with the new RenPy (i.e. with gui.rpy present.), this will mean making some gui art now that I don't have access to the old theme.
*Next thing to do: Code in all the sprite emotion and camera movement for Close Shave Sprite Sections
*Other Thing to Do: Code in all CG and special animation stuff
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Chekhov
Newbie
Posts: 14
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 » Wed Jul 11, 2018 9:44 am

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: No registered users