'show text "xxxx"' in python ?

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
ihentai
Newbie
Posts: 22
Joined: Wed Mar 21, 2007 6:24 pm
Contact:

'show text "xxxx"' in python ?

#1 Post by ihentai »

How to convert from ren'py

Code: Select all

show text "xxxx"
PS I don't know how i should generate a image object from text....

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#2 Post by PyTom »

You can create a Text object. This is a displayable, which can be used like any other displayable, and shows text with a font.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

#3 Post by monele »

Code: Select all

thetext = Text("My text!")
renpy.show("mytext", [Position(xpos=.5, ypos=.5, xanchor=0.5, yanchor=0.5)], what=thetext)
That's python code, so you should either put this in a python block or add "$" in of each line.
The first line creates a new variable which holds a Text object. The text object contains the text "My text!".
The second line shows a sprite named "mytext" at the center of the screen using the previously created object (what=thetext).

Just differenciate the object variable (thetext) and the sprite (mytext) and you'll be good ^^.

Just as an example, once displayed, you'll want to do this to make it disappear :

Code: Select all

renpy.hide("mytext")

Also, a note for savegames... You don't have to define "thetext" in some init block. You can define this just when you need it, right in the story script. BUT... that means it will be considered as something new/changed and will be saved. Therefore, try to reuse "thetext" variable as much as possible so it only saves *one* thing.

Good example :

Code: Select all

thetext = Text("something")
thetext2 = Text("something else")
...
thetext = Text("Still something else, reusing thetext!")
Bad exemple in my opinion :

Code: Select all

thetext = Text("something")
...
othertext = Text("balbla")
...
anothertext = Text("...")
...
etc...

ihentai
Newbie
Posts: 22
Joined: Wed Mar 21, 2007 6:24 pm
Contact:

#4 Post by ihentai »

monele wrote:

Code: Select all

thetext = Text("My text!")
renpy.show("mytext", [Position(xpos=.5, ypos=.5, xanchor=0.5, yanchor=0.5)], what=thetext)
Thanks !!!! That really describes a renpy.show behavior ! I cannot figure that way of using it it from documentation. It was here - but the formal way of docs description stop me from understanding.

So - that piece of code MUST :) go into doc for renpy.show function !!!

Post Reply

Who is online

Users browsing this forum: No registered users