I need help for a "life indicator"

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.
Message
Author
neohin
Newbie
Posts: 4
Joined: Thu Jun 14, 2007 12:57 pm
Location: Mexico
Contact:

I need help for a "life indicator"

#1 Post by neohin »

Hi everyone!
I discovered renpy about a month ago and i am currently developing a dating sim game with it and i have some problems i hope you can help me to resolve.

In the "demo" game included there is something about "life indicators" (those used for battles), can i have them all the game on?

I mean, i want each character to have a "Love indicator" and each time you answer or do something the character likes the indicator level goes up till the end of the game. Could this be possible?

....any suggestion?
-The moment i wake up, before i put on my makeup i say a little prayer for you.-

Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

#2 Post by Criptych »

This isn't quite the same, but you could probably play with it to get what you want. For instance, instead of ui.vbox() ... ui.close() you might use:

Code: Select all

        ui.bar(range=max_love_points,value=my_love_points,
               xpos=0.5,ypos=0.02,xanchor=0.5,yanchor=0.0)
Computers are useless. They can only give you answers. —Pablo Picasso

Image

neohin
Newbie
Posts: 4
Joined: Thu Jun 14, 2007 12:57 pm
Location: Mexico
Contact:

#3 Post by neohin »

Er..i don't quite understand...
-The moment i wake up, before i put on my makeup i say a little prayer for you.-

Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

#4 Post by Criptych »

neohin wrote:In the "demo" game included there is something about "life indicators" (those used for battles), can i have them all the game on?
I assume you mean display the indicator throughout the game, right?
PyTom wrote:Overlays are used to display information above the scene currently displayed. The overlay is regenerated each time an interaction with the user begins, making it suitable for displaying to the user things like statistics or dates.
[...]
Overlays are set up by adding to the config.overlay_functions list [...]. These functions are called for each interaction, which allows the overlay to change to reflect the status of game variables.
If you want to display an indicator with the text onscreen, you need to add a function to this list that creates the bar.

Code: Select all

# First, set up the variables and functions...

init python:
    $ max_love_points = 50 # total available points
    $ my_love_points  =  0 # current points

    def love_indicator():
        ui.bar(range=max_love_points,value=my_love_points,
               xpos=0.5,ypos=0.02,xanchor=0.5,yanchor=0.0)
    config.overlay_functions.append(love_indicator)

# ... then change the points value as the game progresses.

    menu:
        "Where should we go?"

        "To a movie":
            "... That was a bust. How could I know she loved horror flicks?"
            "{i}I{/i} ended up clinging onto {i}her{/i} in fear."
            $ my_love_points += 2 # Well, not bad.

        "To the park":
            "... We decided to take a walk in the park."
            "Halfway around the lake, she unexpectedly took hold of my hand."
            $ my_love_points += 5 # Wow! Good going!
Hope this helps. I have a tendency to be a little obtuse.
Computers are useless. They can only give you answers. —Pablo Picasso

Image

neohin
Newbie
Posts: 4
Joined: Thu Jun 14, 2007 12:57 pm
Location: Mexico
Contact:

#5 Post by neohin »

ohhh, that changes all O.O
got it, thanks for teh help!
-The moment i wake up, before i put on my makeup i say a little prayer for you.-

neohin
Newbie
Posts: 4
Joined: Thu Jun 14, 2007 12:57 pm
Location: Mexico
Contact:

#6 Post by neohin »

um...i have a problem (again)
When i try to run the game the script tells me it's expecting for a statement:

--------------
On line 11 of C:\Documents and Settings\Carla\Mis documentos\renpy-6.2.0-full\renpy-6.2.0\Dream Dating STH version/game/script.rpy: expected statement.
def love_indicator():

^

On line 14 of C:\Documents and Settings\Carla\Mis documentos\renpy-6.2.0-full\renpy-6.2.0\Dream Dating STH version/game/script.rpy: expected statement.
config.overlay_functions.append(love_indicator)
------------------


And then it tells me it's not waiting for an empty block:

------------
On line 143 of C:\Documents and Settings\Carla\Mis documentos\renpy-6.2.0-full\renpy-6.2.0\Dream Dating STH version/game/script.rpy: choice menuitem expects a non-empty block.
"So...what's your name?":

^
--------------


I've tried to fix it but the same message keeps appearing...sorry..i'm not too brilliant at this.
-The moment i wake up, before i put on my makeup i say a little prayer for you.-

Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

#7 Post by Criptych »

Hmmm... oh!

Try removing the $-symbols from the first two lines. I forgot, you don't need those in a python block.

(Note to self: Start testing code before posting it...! :oops: )
Computers are useless. They can only give you answers. —Pablo Picasso

Image

Guest

Re: I need help for a "life indicator"

#8 Post by Guest »

omg!!!
*slaps herself*

It's true, the $ symbols!!!
How can i be so stupid?

thanks a lot!

Guest

Re: I need help for a "life indicator"

#9 Post by Guest »

Okay then, i've removed the $ symbols...
but still i think your code is wrong, at least coz the script tells me there's an error here:

--------------
$ def love_indicator():
ui.bar(range=max_love_points,value=Tails_love_points,
xpos=0.5,ypos=0.02,xanchor=0.5,yanchor=0.0)
config.overlay_functions.append(love_indicator)
-------------------

In the first and last lines to be perfectly honest.

-----------------------------------------

On line 393 of C:\Documents and Settings\Carla\Mis documentos\renpy-6.2.0-full\renpy-6.2.0\Dream Dating STH version/game/script.rpy: expected statement.
ui.bar(range=max_love_points,value=Tails_love_points,

xpos=0.5,ypos=0.02,xanchor=0.5,yanchor=0.0)

^

On line 395 of C:\Documents and Settings\Carla\Mis documentos\renpy-6.2.0-full\renpy-6.2.0\Dream Dating STH version/game/script.rpy: expected statement.
config.overlay_functions.append(love_indicator)

^

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: I need help for a "life indicator"

#10 Post by monele »

In the given example, there are two parts : the init block (ending with "config.overlay_functions.append(love_indicator)") and then a menu part which should be in a label block :

Code: Select all

label somemenu:
    menu:
        "Where should we go?"

        "To a movie":

# etc, etc...
Maybe that's why it fails?

Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

Re: I need help for a "life indicator"

#11 Post by Criptych »

Guest wrote:Okay then, i've removed the $ symbols...
but still i think your code is wrong, at least coz the script tells me there's an error here:

--------------
$ def love_indicator():
ui.bar(range=max_love_points,value=Tails_love_points,
xpos=0.5,ypos=0.02,xanchor=0.5,yanchor=0.0)
config.overlay_functions.append(love_indicator)
-------------------
All right, I looked up some more details about the ui.bar function. It seems instead of using "range=<range>,value=<value>" you just need to have "<range>,<value>". I got a different error message, however: "ValueError: unpack tuple of wrong size." So this may not be what caused your error.

Also, remember to take out the $s and put it in a python block. I'm not sure but I don't think python defs work in straight Ren'Py code.

As for the "empty block" error, make sure there's something under the menu choice to be executed, and that it's properly indented as a block. If you don't want anything there just yet (or at all) put a pass statement, just so there's something.
monele wrote:In the given example, there are two parts : the init block (ending with "config.overlay_functions.append(love_indicator)") and then a menu part which should be in a label block
That's exactly right. The init block just sets up the variables and functions you need. The menu is just an example of how to change the values while your script is running, specifically the $ my_love_points += 2 part. You can also use $my_love_points -= 2 to deduct from the player's points.

P.S. For more control over positioning the bar on the screen, read up in the manual about Widgets. You may also want to move the config.overlay_functions.append(love_indicator) statement out of the init block and into your script at the point you want it to show up: I found that when it's in the init block, it shows up for a moment right before the main menu-- oops!
Computers are useless. They can only give you answers. —Pablo Picasso

Image

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: I need help for a "life indicator"

#12 Post by PyTom »

No, you don't want to update config.overlay_functions (or any config variable, for that matter) once the game has started running. This is because the values of the config variables are not save, and so may be wrong when the game starts running.

Instead, you want to conditionally show the love bar.

Code: Select all

init python:
    def show_love_bar():
        if love_points is None:
            return

        ui.bar(100, love_points, xmaximum=200, xalign=.99, yalign=.1)

    config.overlay_functions.append(show_love_bar)

    love_points = None

labels start:

    $ love_points = 0
    "No love points."

    $ love_points = 50
    "50 love points."
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

-Neohin

Re: I need help for a "life indicator"

#13 Post by -Neohin »

I used the code you gave me (Tom)
but...


On line 2 of C:\Documents and Settings\Carla\Mis documentos\renpy-6.2.0-full\renpy-6.2.0\Dream Dating STH version/game/script.rpy: expected statement.
def show_love_bar():

^

On line 4 of C:\Documents and Settings\Carla\Mis documentos\renpy-6.2.0-full\renpy-6.2.0\Dream Dating STH version/game/script.rpy: expected statement.
config.overlay_functions.append(show_love_bar)

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: I need help for a "life indicator"

#14 Post by PyTom »

Can you copy in the code? I suspect you're using "init" instead of the fairly new "init python", but it helps to know exactly what you're doing.
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

Free Time Machine
Regular
Posts: 42
Joined: Fri Jun 15, 2007 9:45 am
Location: Philly, USA
Contact:

Re: I need help for a "life indicator"

#15 Post by Free Time Machine »

...Now, how would you go about displaying that "love indicator" during a date scene, but hiding it at all other times?
"HOLD ON TIGHT" ~ Outfits and expressions, where art thou? And why does Elsa's face look so awful??? *bangs head in*

Everytime you delete a traceback, someone else gets it. -PyTom

Post Reply

Who is online

Users browsing this forum: Google [Bot]