Screen buttons and if statement problem

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
Kaktusz
Newbie
Posts: 4
Joined: Mon Oct 31, 2016 2:09 pm
Deviantart: Kaktus-Art
Contact:

Screen buttons and if statement problem

#1 Post by Kaktusz » Mon Oct 31, 2016 2:43 pm

Hello everyone,
It's my first post here.
I was reading before many posts, when some error pop's out, but it didn't helped me.
Okay, so first...
I tried to make screen buttons, one for fraction points and other for stats points of player.
I wrote this (sorry i don't know how to paste my .rpy docs, there is no problem with indentation):

Code: Select all

screen button:
    vbox xalign 1.0 yalign 0.1:
        textbutton "Punkty frakcji" action ui.callsinnewcontext("aff_screen_label")
screen aff_screen:
    frame:
        has vbox
        text "Wilkołaki: [werewolfs_points] pkt"
        text "Wampiry: [vampires_points] pkt"
        text "Ludzie: [people_points] pkt"
        text "Elfy: [elves_points] pkt"
        text "Orkowie: [orks_points] pkt"
        textbutton "Wróć" action Return()
        
label aff_screen_label:
    call screen aff_screen
    return
##
screen button:
    vbox xalign 0.1 yalign 0.1:
        textbutton "Punkty statystyk" action ui.callsinnewcontext("stats_screen_label")
screen stats_screen:
    frame:
        has vbox
        text "Charyzma: [charm_points] pkt"
        text "Siła: [strenght_points] pkt"
        text "Inteligencja: [intelligance_points] pkt"
        text "Zręczność: [agility_points] pkt"
        text "Szczęście: [luck_points] pkt"
        textbutton "Wróć" action Return()
        
label stats_screen_label:
    call screen stats_screen
    return
When I run the game, last screen button i wrote show, but the first one didn't.

My second problem is:
When character can make a choice, i wrote some effects, but it make an error. :(

My code:

Code: Select all

    "Uciekłaś z królestwa":
        $ big_escape = True
        if race_werewolf == True:
            $ werewolfs_points -= 100
        elif race_vampire == True:
            $ vampires_points -= 100
        elif race_ork == True:
            $ orks_points -= 100
        elif race_human == True:
            $ people_points -= 100
        elif race_elves == True:
            $ elves_points -= 100
And the error:
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/script.rpy", line 253, in script
if race_werewolf == True:
File "game/script.rpy", line 253, in <module>
if race_werewolf == True:
NameError: name 'race_werewolf' is not defined

This error pop's up when i choose anything else than werewolf, and if i chooce werewolf than an error with another race pop's up.

Thank you so much in advance, to anyone who can help. :D

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Screen buttons and if statement problem

#2 Post by Ocelot » Mon Oct 31, 2016 3:17 pm

First: did you notice that you have two screens named "button"? How is the game supposed to differentiate them?

Second: you need to define variables before using them. I believe, you do not set other variables to False when you choose your race. You need to give them all sensible default values. Like that:

Code: Select all

default race_werewolf = False
default race_vampire = False
default race_ork = False
default race_human = False
default race_elves = False
< < insert Rick Cook quote here > >

Kaktusz
Newbie
Posts: 4
Joined: Mon Oct 31, 2016 2:09 pm
Deviantart: Kaktus-Art
Contact:

Re: Screen buttons and if statement problem

#3 Post by Kaktusz » Mon Oct 31, 2016 3:32 pm

Ocelot wrote:First: did you notice that you have two screens named "button"? How is the game supposed to differentiate them?
Thanks you!
Where should i put the name of buttons?

// Sorry i'm sooo new to Renpy

And my problem with if statement is solved thanks you <3

Post Reply

Who is online

Users browsing this forum: No registered users