Values not showing up with ui.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
bobbk
Regular
Posts: 46
Joined: Tue Feb 09, 2010 8:36 am
Contact:

Values not showing up with ui.text

#1 Post by bobbk »

I can't get values to show up inside ui.text, example:

$ ui.text("To get to the next screen, click %(playerscore)d")

It comes back displaying %(playerscore)d in the UI. With dialogue statements it shows the value fine... any help would be awesome, thanks!

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Values not showing up with ui.text

#2 Post by Alex »

Try

Code: Select all

$ ui.text ("To get to the next screen, click %d" %(playerscore) )
Note: <%d> is used if the <playerscore>`s value is data (a number), and <%s> - if string (some text), even if string is "123".

... and if you need to show several variables it would be like

Code: Select all

$ ui.text ("%d some text %d%s" %(data_var, another_data_var, string_var) ) # the order of variables is important
Last edited by Alex on Sat Feb 13, 2010 4:06 pm, edited 2 times in total.

bobbk
Regular
Posts: 46
Joined: Tue Feb 09, 2010 8:36 am
Contact:

Re: Values not showing up with ui.text

#3 Post by bobbk »

That's not working either, why did you move the value outside the text string?

the value I'm trying to display is a number and not a string

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Values not showing up with ui.text

#4 Post by Alex »

Could you show the part of your code...

bobbk
Regular
Posts: 46
Joined: Tue Feb 09, 2010 8:36 am
Contact:

Re: Values not showing up with ui.text

#5 Post by bobbk »

Playerscore doesn't display a numeric value, instead if displays exactly the way it's written in the string.

Code: Select all

init:
    image bg slums = "bg_blur.jpg"
    
    $ playerscore = 1
    
    python:
        def testoverlay():
            ui.text("Test")
            
        config.overlay_functions.append(testoverlay)
    
# The game starts here.
label start:
    
    scene bg slums
    
    Test UI
        
# Clicking on image map opens the UI below.
    $ ui.imagemap("bg_slumtest.jpg", "bg_slumtest2.jpg", [
                           (100, 100, 300, 400, "choice1"),
                          ]) 
    
    $ result= ui.interact()
    if result == "choice1":   
        $ ui.vbox(xpos=.3, ypos=1)
        $ ui.imagebutton("btn_taxi_killer_no_text.png", "btn_taxi_killer_no_text_over.png", clicked=ui.jumps('startthird'))    
        $ ui.close()
        $ ui.vbox(xpos=.2, ypos=.25)
        $ ui.text("This is the score %(playerscore)d ")
        $ ui.close()

"Stupid UI!"
Also for some reason I can't figure out how to make my menu wait for an instruction, when the UI opens the script keeps running and displays "stupid UI!" i'd prefer for it to wait for a click before doing anything further

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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:

Re: Values not showing up with ui.text

#6 Post by PyTom »

bobbk wrote:Playerscore doesn't display a numeric value, instead if displays exactly the way it's written in the string.
Interpolation isn't automatic when in python code. You need to tell Ren'Py what you want to interpolate:

Code: Select all

    if result == "choice1":   
        $ ui.vbox(xpos=.3, ypos=1)
        $ ui.imagebutton("btn_taxi_killer_no_text.png", "btn_taxi_killer_no_text_over.png", clicked=ui.jumps('startthird'))    
        $ ui.close()
        $ ui.vbox(xpos=.2, ypos=.25)
        $ ui.text("This is the score %d " % playerscore)
        $ ui.close()

        pause

"Stupid UI!"
Also for some reason I can't figure out how to make my menu wait for an instruction, when the UI opens the script keeps running and displays "stupid UI!" i'd prefer for it to wait for a click before doing anything further
You'll need to cause an interaction to occur. If you want clicking outside of the button to cause the game to advance, you can use pause as given above. Otherwise, you can call ui.interact.
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

bobbk
Regular
Posts: 46
Joined: Tue Feb 09, 2010 8:36 am
Contact:

Re: Values not showing up with ui.text

#7 Post by bobbk »

Fixed! Alex gave the same advice but I think I had a typo.

Pause is a pretty simple solution to something I couldn't quite figure out =)

thanks Alex & Pytom!

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Values not showing up with ui.text

#8 Post by Alex »

Oops, I was late...))

Post Reply

Who is online

Users browsing this forum: Google [Bot]