[SOLVED] Defining a bespoke python function to render screen text

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
thirstyoctopus
Regular
Posts: 72
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

[SOLVED] Defining a bespoke python function to render screen text

#1 Post by thirstyoctopus » Sun Apr 07, 2019 12:54 pm

Hi guys

I'm having a bit of a problem with this one. I have a screen in my game which is basically an open notepad with the main character's notes in. I want to use a specific font for these notes but I don't want to have constantly define the font within the text statement, which is what I had done:

Code: Select all

text _("{font=Fonts/JandaEverydayCasual.ttf}My text goes here{/font}")
so, I wrote a python function to call when I need to write notebook text, which included the size and font, which I decided to define in gui.rpy:

gui.rpy:

Code: Select all

define gui.notebook_text_font = "Fonts/JandaEverydayCasual.ttf"
screens.rpy:

Code: Select all

init python:
    def nbText(message):
        return text message size 18 font gui.notebook_text_font
then in my notepad screen, I'd simply pass the text through the function:

Code: Select all

$ nbText("I think she likes me!")
But I keep getting a syntax error within the function where I'm returning the text. Am I even doing this correctly? It's very hard to find any examples online, and I've kind of been referencing some code in another game but unfortunately there's nothing that actually does what I'm trying to do. I also need to define the color come to think of it ....
Last edited by thirstyoctopus on Sun Apr 07, 2019 1:19 pm, edited 1 time in total.

User avatar
thirstyoctopus
Regular
Posts: 72
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: Defining a bespoke python function to render screen text

#2 Post by thirstyoctopus » Sun Apr 07, 2019 1:18 pm

OK I managed to solve it!

Instead of using a function I define some style properties like so:

Code: Select all

style notebook_text:
    ypos 18
    line_spacing 12
    font gui.notebook_text_font
    size 18
    color "#666666"
then, in my notebook screen I simply used the style prefix:

Code: Select all

style prefix "notebook"
And then wrote text such as:

Code: Select all

text "Here are some cool scripty notes!"
And it worked! So, I guess it wasn't so complicated after all! Hope this helps someone, maybe...

User avatar
thirstyoctopus
Regular
Posts: 72
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: [SOLVED] Defining a bespoke python function to render screen text

#3 Post by thirstyoctopus » Sun Apr 07, 2019 1:20 pm

Sorry I meant style_prefix, not style prefix.

Post Reply

Who is online

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