show variable in right corner [SOLVED]

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
de_nederlander
Newbie
Posts: 21
Joined: Thu Aug 04, 2016 8:26 am
Contact:

show variable in right corner [SOLVED]

#1 Post by de_nederlander »

Maybe I'm asking quite some questions lately but,

how do I show a variable in the right corner of the screen, I would like the player to see how much coins he has, and how much points.

I've tried looking for how ui.text works but I just can't see how to style them and place them.

thanks for your help.
Last edited by de_nederlander on Thu Aug 11, 2016 11:32 am, edited 1 time in total.

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: show variable in right corner

#2 Post by Iylae »

A simple example:

Code: Select all

screen show_money():
    frame:
        xalign 1.0
        text str(money) 


label start:
    
    default money = 10
    
    show screen show_money
    
    "test"
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

de_nederlander
Newbie
Posts: 21
Joined: Thu Aug 04, 2016 8:26 am
Contact:

Re: show variable in right corner

#3 Post by de_nederlander »

Iylae wrote:A simple example:

Code: Select all

screen show_money():
    frame:
        xalign 1.0
        text str(money) 


label start:
    
    default money = 10
    
    show screen show_money
    
    "test"
it works, but is there a way to adjust the size and the position?

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: show variable in right corner

#4 Post by Iylae »

see https://www.renpy.org/doc/html/screens.html#text and follow the links for the properties you can apply to text.

also see https://www.renpy.org/doc/html/screens.html#frame for the links for the properties you can apply to the frame
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

de_nederlander
Newbie
Posts: 21
Joined: Thu Aug 04, 2016 8:26 am
Contact:

Re: show variable in right corner

#5 Post by de_nederlander »

Iylae wrote:see https://www.renpy.org/doc/html/screens.html#text and follow the links for the properties you can apply to text.

also see https://www.renpy.org/doc/html/screens.html#frame for the links for the properties you can apply to the frame
everything works with this, but it doesn't seem to update once it more money is added.
do I have to hide and show it again, or is there another way?

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: show variable in right corner

#6 Post by Iylae »

de_nederlander wrote:do I have to hide and show it again
That's the only way I know. I would recommend (if you know how) building a function that both updates the money and refreshes (re-shows) the screen. That way you won't ever forget to update the screen.
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

de_nederlander
Newbie
Posts: 21
Joined: Thu Aug 04, 2016 8:26 am
Contact:

Re: show variable in right corner

#7 Post by de_nederlander »

Iylae wrote:
de_nederlander wrote:do I have to hide and show it again
That's the only way I know. I would recommend (if you know how) building a function that both updates the money and refreshes (re-shows) the screen. That way you won't ever forget to update the screen.
okay thanks a lot.

I've seen you answering quite some questions lately, so I hope you are able to help a lot more people.

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: show variable in right corner

#8 Post by Iylae »

As a Karate Instructor in my spare time, I've come to appreciate that a viable way to improve at something is to teach it to others.

There's a quote I'm fond of though I forget the source: "docendo disco, scribendo cogito" meaning "I learn by teaching, I think by writing".

Sadly my knowledge is moderate and narrow at best, so I can't help with most people's problems with Ren'Py as a whole, but basic programming isn't too much of a hassle for me.
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

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

Re: show variable in right corner

#9 Post by Alex »

de_nederlander wrote:everything works with this, but it doesn't seem to update once it more money is added.
do I have to hide and show it again, or is there another way?
But what's the code to increase the money amount?

de_nederlander
Newbie
Posts: 21
Joined: Thu Aug 04, 2016 8:26 am
Contact:

Re: show variable in right corner

#10 Post by de_nederlander »

Alex wrote:
de_nederlander wrote:everything works with this, but it doesn't seem to update once it more money is added.
do I have to hide and show it again, or is there another way?
But what's the code to increase the money amount?
I use $ money += earn

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

Re: show variable in right corner [SOLVED]

#11 Post by Alex »

If you do it this way, the value of money variable should update in screen.

de_nederlander
Newbie
Posts: 21
Joined: Thu Aug 04, 2016 8:26 am
Contact:

Re: show variable in right corner [SOLVED]

#12 Post by de_nederlander »

Alex wrote:If you do it this way, the value of money variable should update in screen.
it doesn't

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

Re: show variable in right corner [SOLVED]

#13 Post by Alex »

This code works

Code: Select all

screen my_scr():
    text "money: [money]" size 35 color "#c00" align (0.5, 0.05)
    
default money = 100

label start:
    "..."
    show screen my_scr
    "."
    $ money += 10
    "?"
So check if "earn" is not zero.

de_nederlander
Newbie
Posts: 21
Joined: Thu Aug 04, 2016 8:26 am
Contact:

Re: show variable in right corner [SOLVED]

#14 Post by de_nederlander »

Alex wrote:This code works

Code: Select all

screen my_scr():
    text "money: [money]" size 35 color "#c00" align (0.5, 0.05)
    
default money = 100

label start:
    "..."
    show screen my_scr
    "."
    $ money += 10
    "?"
So check if "earn" is not zero.
it works now, I used str(money) instead of [money], thanks, my code is a lot smaller now

Post Reply

Who is online

Users browsing this forum: Semrush [Bot]