Text in custom displayables

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
Queex
Regular
Posts: 46
Joined: Sat Mar 14, 2015 9:47 am
Contact:

Text in custom displayables

#1 Post by Queex »

I want to add a text object to the custom displayable I'm writing; but can't find an example to work from. Adding images is simple enough, using the example in the manual, but I'm foxed at trying to add text. Using renpy.displayable() seems to require the displayable to be registered in renpy, and that's not going to be feasible. I swear I found a way to draw to a screen directly one time, but I can't find an example anywhere.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Text in custom displayables

#2 Post by xela »

At what time is is appropriate to say "WTF"? :roll: ;)

I've thrown a clearcut example of that at you just a day or two ago: http://lemmasoft.renai.us/forums/viewto ... xt#p407163
Like what we're doing? Support us at:
Image

User avatar
Queex
Regular
Posts: 46
Joined: Sat Mar 14, 2015 9:47 am
Contact:

Re: Text in custom displayables

#3 Post by Queex »

None of that is usage within a custom Displayable object. Surely nothing involving a show method is applicable? What I think I need is the pure python invocation of creating a text object, but that's what I can't find any documentation of.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
...
  File "game/battle.rpy", line 34, in render
    name=Text(chars_name[self.index]) # No
...
NameError: global name 'Text' is not defined

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Text in custom displayables

#4 Post by xela »

Can you show the code where such an absurdity occurs?

Text is bound in Ren'Py's store to a renpy.text.text.Text. There is nothing you can do to delete it from global namespace except of explicitly unbind the binding by del Text. This error:
NameError: global name 'Text' is not defined
is one of the last errors I'd expect from the engine :(

==>
Meaning that I can write a UDD for you that uses the Text binding from global namespace directly that will work with ANY fresh Ren'Py project for which Text was introduced many years ago.
Like what we're doing? Support us at:
Image

User avatar
Queex
Regular
Posts: 46
Joined: Sat Mar 14, 2015 9:47 am
Contact:

Re: Text in custom displayables

#5 Post by Queex »

It's inside the render() method of a class extending Displayable; so bare renpy directives didn't work.

Code: Select all

        def render(self, width, height, st, at):
            child_render=renpy.render(self.child, width, height, st, at)
            self.width, self.height = child_render.get_size()
            self.width+=40
            self.height+=40
            
            name=renpy.text.text.Text(chars_name[self.index]) 
            
            render = renpy.Render(self.width, self.height)
            
            render.blit(child_render, (20,20))
            render.blit(renpy.render(name,self.width,height, st ,at),(0,0),False)
            
            return render
worked perfectly, however! Many thanks.

And now I can put the instantiation somewhere more sensible and just put the rendering portion in the render method. I still feel like there should be a more elegant way of handling it, grabbing the code that renders text directly rather than creating a child object, but that'll do for now.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Text in custom displayables

#6 Post by xela »

From .rpy file, it should work (in most cases) but as long as you got it to fly, I don't expect any further issues ;)
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]