Name box padding only if side image is present

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
cirnoe
Newbie
Posts: 23
Joined: Fri Sep 04, 2015 1:28 pm
Contact:

Name box padding only if side image is present

#1 Post by cirnoe » Mon May 17, 2021 7:24 pm

Hello!
I have a feeling this is a pretty basic question but somehow I can’t find any info on it. I’d like the name box to have 500px padding only if the side image is displayed, otherwise, I’d like it to stay at 300px padding. I’m not sure how to configure this, could anyone point me in the right direction? Thank you so much! :D

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: Name box padding only if side image is present

#2 Post by emz911 » Tue May 25, 2021 8:11 pm

One way you could do it is to modify the say screen in screens.rpy. Add a condition to check if SideImage() is present, and change the namebox position beneath it.

User avatar
cirnoe
Newbie
Posts: 23
Joined: Fri Sep 04, 2015 1:28 pm
Contact:

Re: Name box padding only if side image is present

#3 Post by cirnoe » Wed May 26, 2021 3:30 pm

emz911 wrote:
Tue May 25, 2021 8:11 pm
One way you could do it is to modify the say screen in screens.rpy. Add a condition to check if SideImage() is present, and change the namebox position beneath it.
Thank you for the reply! I will look into this :)

User avatar
cirnoe
Newbie
Posts: 23
Joined: Fri Sep 04, 2015 1:28 pm
Contact:

Re: Name box padding only if side image is present

#4 Post by cirnoe » Thu May 27, 2021 8:06 am

emz911 wrote:
Tue May 25, 2021 8:11 pm
One way you could do it is to modify the say screen in screens.rpy. Add a condition to check if SideImage() is present, and change the namebox position beneath it.
Hi! Sorry for the second reply. I'm pretty new with python so I can't seem to figure out the syntax for this statement. right now I wrote something along this line

Code: Select all

    
    if SideImage() = True:
        style "namebox"
    else 
        xpos = 200
Could you tell me how to do it correctly? Thank you in advance!

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: Name box padding only if side image is present

#5 Post by emz911 » Thu May 27, 2021 7:32 pm

A couple of notes first looking at your code:
1) Conditional statements (if/while etc.) always take a double equal sign (== True) instead of a single equal sign (= True) which is used to define or change variables
2) In renpy screens, you won't need the = equal sign between arguments, so you should do "xpos 200" instead of "xpos = 200"
These two points would lead to errors if you try to run the game, so don't forget that screen language is different from script language!

Since "add SideImage()" would show a Null() displayable if no side image is present, I imagined this code would work, but it didn't:

Code: Select all

if who is not None:
    window:
        id "namebox"
        style "namebox"
        text who id "who"
        if SideImage(): #other ones I tried along the lines: if SideImage() == Null(), if not SideImage()... etc.
            xpos gui.name_xpos #note that I didn't wrap the entire style "namebox" inside here, because that might mess up your other style settings, so all you need to change is the xpos, this would only replace the xpos and nothing else under the namebox style
        else:
            xpos 200
Unfortunately the condition for SideImage() did not work as intended, perhaps because the function for SideImage() don't work so simply and did not return Null(). Anyways, since I'm no expert and couldn't find the SideImage() function underneath the hood, I searched the documentation for ways to get around it. This is what I finally found:
renpy.get_say_image_tag()
Returns the tag corresponding to the currently speaking character (the image argument given to that character). Returns None if no character is speaking or the current speaking character does not have a corresponding image tag. https://www.renpy.org/doc/html/displayi ... _image_tag
Given the description, this could work with side images, so I altered the above code to:

Code: Select all

if who is not None:
    window:
        id "namebox"
        style "namebox"
        text who id "who"
        if renpy.get_say_image_tag():
            xpos gui.name_xpos
        else:
            xpos 200
Tested it and it worked! However, I only tested this with side images, if you are using "show image" and side images at the same time, be aware of the speaking character and its image tag, as that might affect what is returned with the renpy.get_say_image_tag().

User avatar
cirnoe
Newbie
Posts: 23
Joined: Fri Sep 04, 2015 1:28 pm
Contact:

Re: Name box padding only if side image is present

#6 Post by cirnoe » Fri May 28, 2021 9:29 am

emz911 wrote:
Thu May 27, 2021 7:32 pm
A couple of notes first looking at your code:
1) Conditional statements (if/while etc.) always take a double equal sign (== True) instead of a single equal sign (= True) which is used to define or change variables
2) In renpy screens, you won't need the = equal sign between arguments, so you should do "xpos 200" instead of "xpos = 200"
These two points would lead to errors if you try to run the game, so don't forget that screen language is different from script language!

Since "add SideImage()" would show a Null() displayable if no side image is present, I imagined this code would work, but it didn't:

Code: Select all

if who is not None:
    window:
        id "namebox"
        style "namebox"
        text who id "who"
        if SideImage(): #other ones I tried along the lines: if SideImage() == Null(), if not SideImage()... etc.
            xpos gui.name_xpos #note that I didn't wrap the entire style "namebox" inside here, because that might mess up your other style settings, so all you need to change is the xpos, this would only replace the xpos and nothing else under the namebox style
        else:
            xpos 200
Unfortunately the condition for SideImage() did not work as intended, perhaps because the function for SideImage() don't work so simply and did not return Null(). Anyways, since I'm no expert and couldn't find the SideImage() function underneath the hood, I searched the documentation for ways to get around it. This is what I finally found:
renpy.get_say_image_tag()
Returns the tag corresponding to the currently speaking character (the image argument given to that character). Returns None if no character is speaking or the current speaking character does not have a corresponding image tag. https://www.renpy.org/doc/html/displayi ... _image_tag
Given the description, this could work with side images, so I altered the above code to:

Code: Select all

if who is not None:
    window:
        id "namebox"
        style "namebox"
        text who id "who"
        if renpy.get_say_image_tag():
            xpos gui.name_xpos
        else:
            xpos 200
Tested it and it worked! However, I only tested this with side images, if you are using "show image" and side images at the same time, be aware of the speaking character and its image tag, as that might affect what is returned with the renpy.get_say_image_tag().
omg wow, the code worked perfectly!!! I really appreciate the effort you put in for your detailed explanation and help, and I'll take note of your general coding advice as well :)) Thank you so much for your quick and informative reply!! :D

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: Name box padding only if side image is present

#7 Post by emz911 » Fri May 28, 2021 1:05 pm

You are very welcome!! Learning code is basically a process of trial-and-error and flipping through documentations :lol:, so I strongly recommend looking up keywords on the Renpy documentation (or this forum) whenever you are stuck: https://www.renpy.org/doc/html/index.html
Anyways, glad to help!!

Post Reply

Who is online

Users browsing this forum: No registered users