Displaying variables (or scores) in game 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
MrCat
Newbie
Posts: 10
Joined: Sun Oct 13, 2019 9:33 am
Contact:

Displaying variables (or scores) in game text?

#1 Post by MrCat »

Hey folks,

I'm well new still and be trying my hardest but I can't seem to find the correct way to display variables at the end of or during a game or any info about it, for keeping game scores and such.

I think I've set up some basic variables with

Code: Select all

init:
    $ waster = 0
    $ intuition = 0
    $ lover = 0
    $ normality = 0
    $ human = 0
and hopefully added to them with the likes of:

Code: Select all

label after_choice1:
    if choice1 == "1":
        "You are such a wreckhead!"
        $ waster += 1
    if choice1 == "2":
        "Ummm, was that a good idea?"
        $ human += 1
    if choice1 == "3":
        "Awesomeness!"
But then how do I say for example

Code: Select all

"You awake to find your scores are Waster (variable displayed here)! Intuition (variable displayed here) etc"

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Displaying variables (or scores) in game text?

#2 Post by isobellesophia »

Code: Select all

"You awake to find your scores are Waster [waster]!"
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Displaying variables (or scores) in game text?

#3 Post by Imperf3kt »

Instead of init, it is better to place your variables outside of any label any use default instead of $

Code: Select all

default waster = 0
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

MrCat
Newbie
Posts: 10
Joined: Sun Oct 13, 2019 9:33 am
Contact:

Re: Displaying variables (or scores) in game text?

#4 Post by MrCat »

Wow, awesome folks! Thanks that's perfect :)

MrCat
Newbie
Posts: 10
Joined: Sun Oct 13, 2019 9:33 am
Contact:

Re: Displaying variables (or scores) in game text?

#5 Post by MrCat »

Imperf3kt wrote: Fri Nov 08, 2019 12:35 am Instead of init, it is better to place your variables outside of any label any use default instead of $

Code: Select all

default waster = 0
Just to check, do I need to add the '$' later then when performing additions or subtractions to them?

I'm new to Python and it seems pretty 'plain english liberal and forgiving' haha for want of better words,so far anyhow as I've not delved much in to it yet :) But reading some of the post on this forum I'm quite excited to get my hands proper dirty :D

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Displaying variables (or scores) in game text?

#6 Post by Imperf3kt »

Yes, use $ within your script when modifying the variable
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot], Rhapsy