Life Bar Problems [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
User avatar
Westeford
Regular
Posts: 151
Joined: Mon Jun 19, 2017 4:43 pm
Completed: 12 Hours to Die
Projects: Project Premonition
itch: westeford
Location: United States
Contact:

Life Bar Problems [Solved]

#1 Post by Westeford »

I couldn't wrap my head around the bars code, so I thought I could just make it simpler by using images I designed myself. I haven't even called the screen and I'm already having problems.
This is a lifebar much like Ace Attorney. It starts full, then when the player get's a wrong answer, it penalizes the player. After 5 strikes, the game is over.
Here's my code.

Code: Select all

default life_current = 5
default life_max = 5
    
screen life():
    vbox xalign 1.0 yalign 0.0:
        if life_current = 5:
            add "images/UI/life/life_5.png" #I've tried putting "xalign 1.0 yalign 0.0" here instead of at vbox, but it still doesn't work
        elif life_current = 4:
            add "images/UI/life/life_4.png" #I've tried saying show instead of add.
        elif life_current = 3:
            add "images/UI/life/life_3.png"
        elif life_current = 2:
            add "images/UI/life/life_2.png"
        elif life_current = 1:
            add "images/UI/life/life_1.png"
        else:
            add "images/UI/life/life_0.png"
When I do this I get this.

Code: Select all

I'm sorry, but an uncaught exception occurred.

After initialization, but before game start.
  File "game/truthbullets.rpy", line 4, in analyze_screen
    screen life():
  File "game/truthbullets.rpy", line 4, in analyze
    screen life():
  File "game/truthbullets.rpy", line 4, in analyze
    screen life():
  File "game/truthbullets.rpy", line 5, in analyze
    vbox xalign 1.0 yalign 0.0:
  File "game/truthbullets.rpy", line 5, in analyze
    vbox xalign 1.0 yalign 0.0:
  File "game/truthbullets.rpy", line 6, in analyze
    if life_current = 5:
SyntaxError: invalid syntax (game/truthbullets.rpy, line 6)
Am I missing something?
I appreciate any help on this or for helping me understand bars. Thanks.
Last edited by Westeford on Thu Sep 27, 2018 6:03 pm, edited 1 time in total.

User avatar
kostek00
Regular
Posts: 131
Joined: Wed Mar 28, 2018 5:54 pm
Contact:

Re: Life Bar Problems

#2 Post by kostek00 »

Not sure if this helps but try putting your default stats into init block:

Code: Select all

init:
    default life_current = 5
    default life_max = 5

User avatar
Westeford
Regular
Posts: 151
Joined: Mon Jun 19, 2017 4:43 pm
Completed: 12 Hours to Die
Projects: Project Premonition
itch: westeford
Location: United States
Contact:

Re: Life Bar Problems

#3 Post by Westeford »

kostek00 wrote: Thu Sep 27, 2018 4:57 pm

Code: Select all

init:
    default life_current = 5
    default life_max = 5
Still the same result. Thanks for your input though. :D

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Life Bar Problems

#4 Post by Per K Grok »

Westeford wrote: Thu Sep 27, 2018 4:39 pm
Here's my code.

Code: Select all

default life_current = 5
default life_max = 5
    
screen life():
    vbox xalign 1.0 yalign 0.0:
        if life_current = 5:
            add "images/UI/life/life_5.png" #I've tried putting "xalign 1.0 yalign 0.0" here instead of at vbox, but it still doesn't work
     -----
----

Am I missing something?
I appreciate any help on this or for helping me understand bars. Thanks.
if life_current = 5:
should be
if life_current == 5:

and so on

User avatar
Westeford
Regular
Posts: 151
Joined: Mon Jun 19, 2017 4:43 pm
Completed: 12 Hours to Die
Projects: Project Premonition
itch: westeford
Location: United States
Contact:

Re: Life Bar Problems

#5 Post by Westeford »

Per K Grok wrote: Thu Sep 27, 2018 5:47 pm if life_current = 5:
should be
if life_current == 5:
and so on
Thank you very much it's working now.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]