[SOLVED] Reposition text box temporarily?

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
Semicolonkid
Regular
Posts: 51
Joined: Tue Feb 14, 2017 6:13 pm
Projects: Summoned
itch: semicolonkid
Contact:

[SOLVED] Reposition text box temporarily?

#1 Post by Semicolonkid »

Hello! Simple question, but I've spent a few hours trying to wrap my head around the related answers I've seen and I'm just not getting it.

I'd like to temporarily have the text box display itself at the top of the screen instead of the bottom, and then move it back down again later.

In gui.rpy, there is the line:

Code: Select all

define gui.textbox_yalign = 1.0
If you set this equal to 0.0, the text box is put on top instead of on bottom. Perfect, this is exactly what I want! Except...you can't change this value back and forth at runtime.
I would like to keep the text box on the bottom most of the time, but display it on top every now and then.

Could anyone show me the simplest way to do this? Defining a character or style is fine, I'm just struggling to figure out the syntax for it. Thanks in advance!
Last edited by Semicolonkid on Sun Sep 11, 2022 3:18 pm, edited 2 times in total.
Image

laure44
Regular
Posts: 84
Joined: Mon Mar 08, 2021 10:55 pm
Projects: Arkan'sTower, Gemshine Lorelei!
Location: France
Contact:

Re: Reposition text box temporarily?

#2 Post by laure44 »

Here's one simple way:

Code: Select all

default textbox_top = False

# in your say screen, find the window line and add the condition.

    window:
        id "window"
        if textbox_top:
            yalign 0.0

##
label start:
    "Bottom."
    $textbox_top = True
    "Top."
    $textbox_top = False
    "Bottom again."

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2426
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Reposition text box temporarily?

#3 Post by Ocelot »

There are few ways. Depending on how often you want to do this, you might define a character:
Styling Text and Windows. Keyword arguments beginning with who_, what_, and window_ have their prefix stripped, and are used to style the character name, the spoken text, and the window containing both, respectively.

For example, if a character is given the keyword argument who_color="#c8ffc8", the color of the character's name is changed, in this case to green. window_background="frame.png" sets the background of the window containing this character's dialogue.

Code: Select all

define on_top = Character(window_yalign=0.0)
You can create a function which will create characters based on other characters:

Code: Select all

init python:
    def on_top(char):
        return Character(kind=char, window_yalign=0.0)
# . . .
on_top(my_cool_char) "I am on top!"
You can pass argument to say statement itself:

Code: Select all

my_cool_char "I am on top!" (window_yalign=0.0)
< < insert Rick Cook quote here > >

User avatar
Semicolonkid
Regular
Posts: 51
Joined: Tue Feb 14, 2017 6:13 pm
Projects: Summoned
itch: semicolonkid
Contact:

Re: Reposition text box temporarily?

#4 Post by Semicolonkid »

Both of these are exactly what I was looking for!! Thank you both so much!
Image

User avatar
Semicolonkid
Regular
Posts: 51
Joined: Tue Feb 14, 2017 6:13 pm
Projects: Summoned
itch: semicolonkid
Contact:

Re: Reposition text box temporarily?

#5 Post by Semicolonkid »

laure44 wrote: Sun Sep 11, 2022 2:47 pm Here's one simple way:

Code: Select all

default textbox_top = False

# in your say screen, find the window line and add the condition.

    window:
        id "window"
        if textbox_top:
            yalign 0.0

##
label start:
    "Bottom."
    $textbox_top = True
    "Top."
    $textbox_top = False
    "Bottom again."
Okay, I'm running into an issue with this solution, maybe you can clarify what I'm doing wrong.

I went into screens.rpy and found the style code for the dialogue box. Normally it's:

Code: Select all

style window:
    xalign 0.5
    xfill True
    yalign gui.textbox_yalign
    ysize gui.textbox_height

    background Image("gui/textbox.png", xalign=0.5, yalign=1.0)
But instead, I changed it to this:

Code: Select all

style window:
    xalign 0.5
    xfill True
    if textbox_top:
        yalign 0.0
    else:
        yalign gui.textbox_yalign
    ysize gui.textbox_height

    background Image("gui/textbox.png", xalign=0.5, yalign=1.0)
(I've defined textbox_top elsewhere)
But when I run it, I get this error:
File "game/screens.rpy", line 543: end of line expected.
if textbox_top:


What am I missing here?
Image

laure44
Regular
Posts: 84
Joined: Mon Mar 08, 2021 10:55 pm
Projects: Arkan'sTower, Gemshine Lorelei!
Location: France
Contact:

Re: Reposition text box temporarily?

#6 Post by laure44 »

Semicolonkid wrote: Sun Sep 11, 2022 3:11 pm What am I missing here?
Pretty sure you can't use conditions in styles, which is why I used it in the say screen directly

User avatar
Semicolonkid
Regular
Posts: 51
Joined: Tue Feb 14, 2017 6:13 pm
Projects: Summoned
itch: semicolonkid
Contact:

Re: Reposition text box temporarily?

#7 Post by Semicolonkid »

laure44 wrote: Sun Sep 11, 2022 3:12 pm
Semicolonkid wrote: Sun Sep 11, 2022 3:11 pm What am I missing here?
Pretty sure you can't use conditions in styles, which is why I used it in the say screen directly
Ohh, I see! That's where I kept getting confused.

IT WORKS!! Thanks again so much!!
Image

Post Reply

Who is online

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