Updating Variables in a Simple Screen

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
MattMurdock
Newbie
Posts: 10
Joined: Mon Sep 16, 2019 3:43 pm
Contact:

Updating Variables in a Simple Screen

#1 Post by MattMurdock » Mon Sep 16, 2019 4:05 pm

Okay, so I have a simple screen:

Code: Select all

screen sideScreen(character, year):
    window id "window":
        vbox:
            spacing 10
            
            text character id "[character]"
            text year id "[year]"
Then, I have it initialized in label start as:

Code: Select all

    
    $ character = "Deckard"
    $ year = "484-12-04"

    show screen sideScreen(character, year)
The problem is, if I change "Deckard" into "Batty", the variable does change but it remains "Deckard" on the side screen. So, how would I change this, because part of the game I am making includes jumps to different timelines and so the date must change and the perspective with it.

User avatar
IrinaLazareva
Veteran
Posts: 367
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: IKG
Location: St.Petersburg, Russia
Contact:

Re: Updating Variables in a Simple Screen

#2 Post by IrinaLazareva » Mon Sep 16, 2019 4:26 pm

try

Code: Select all

default character = "Deckard"
default year = "484-12-04"

screen sideScreen():                   # <<<
    window id "window":
        vbox:
            spacing 10

            text "[character]"          # <<<
            text "[year]"               # <<<


label start:
    ' '
    show screen sideScreen
    '!'
    $ character = "Not Deckard"
I advise you to be careful when selecting names for variables. Some names may be reserved. For example, Character()
https://renpy.org/doc/html/reserved.html
There is a light at the end of the tunnel, just pray it's not a train.
___
TODO: unresolved/нерешённое

MattMurdock
Newbie
Posts: 10
Joined: Mon Sep 16, 2019 3:43 pm
Contact:

Re: Updating Variables in a Simple Screen

#3 Post by MattMurdock » Mon Sep 16, 2019 4:38 pm

So, I did that, pretty much similar to how you wrote it, but what occurs now, is that it never shows as 'Deckard'. When I initialize the game, it should be 'Deckard' for a little bit and then change into 'Batty' but now, I initialize it and its automatically 'Batty' even though that variable change hasn't happened yet. However, thanks for the advice on 'character', I changed it into 'primChar'. So:

Code: Select all

label start:

    show screen sideScreen
    
    "Should be Deckard, but is showing as Batty"
    
    $ primChar = "Batty"
    
    "Now is when the change to Batty happens but it is already Batty, so, no appearance of change"

User avatar
IrinaLazareva
Veteran
Posts: 367
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: IKG
Location: St.Petersburg, Russia
Contact:

Re: Updating Variables in a Simple Screen

#4 Post by IrinaLazareva » Mon Sep 16, 2019 5:29 pm

Hmm. should work. Well, you can track the state of the variable: when the game is running, press Shift+D and then click "Variable Viewer"....

At the very least, you can write:

Code: Select all

label start:

    $ primChar = "Deckard"
    
    show screen sideScreen
    
    "Should be Deckard"
This is the equivalent of the lines:

Code: Select all

default primChar = "Deckard"
label start:
    show screen sideScreen
There is a light at the end of the tunnel, just pray it's not a train.
___
TODO: unresolved/нерешённое

MattMurdock
Newbie
Posts: 10
Joined: Mon Sep 16, 2019 3:43 pm
Contact:

Re: Updating Variables in a Simple Screen

#5 Post by MattMurdock » Mon Sep 16, 2019 6:20 pm

IrinaLazareva wrote:
Mon Sep 16, 2019 5:29 pm
Hmm. should work. Well, you can track the state of the variable: when the game is running, press Shift+D and then click "Variable Viewer"....

At the very least, you can write:

Code: Select all

label start:

    $ primChar = "Deckard"
    
    show screen sideScreen
    
    "Should be Deckard"
This is the equivalent of the lines:

Code: Select all

default primChar = "Deckard"
label start:
    show screen sideScreen
I've tried both of them, the result is still the same. By the Variable Viewer, upon initialization, the variable primChar starts off as 'Batty' despite the change to it coming later. For visualization sake, this is what I have:

Code: Select all

default primChar = "Deckard"
default year = "484-12-04"

label start:

    show screen sideScreen
    
    "Hello, you should be Deckard"
    "Are you Deckard?"
    "D.E.C.K."
    "Inspectah Deckard"
    
    $ primChar = "Batty"
    
    "Go Batty now"
    "Batty"
And by the first suggestion, sideScreen is now simply:

Code: Select all

screen sideScreen:
    window id "window":
        vbox:
            spacing 10
            
            text "[primChar]"
            text "[year]"

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

Re: Updating Variables in a Simple Screen

#6 Post by Imperf3kt » Mon Sep 16, 2019 6:33 pm

You might consider changing the variable "year" as well. It is reserved within python datetime, and Ren'Py internals use it.
It could be causing errors.

Might I suggest just "yr"

Is also suggest trying the "delete persistent" and "force recompile" options within the launcher.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter

MattMurdock
Newbie
Posts: 10
Joined: Mon Sep 16, 2019 3:43 pm
Contact:

Re: Updating Variables in a Simple Screen

#7 Post by MattMurdock » Mon Sep 16, 2019 6:45 pm

Imperf3kt wrote:
Mon Sep 16, 2019 6:33 pm
You might consider changing the variable "year" as well. It is reserved within python datetime, and Ren'Py internals use it.
It could be causing errors.

Might I suggest just "yr"

Is also suggest trying the "delete persistent" and "force recompile" options within the launcher.
That worked, thank you!

Post Reply

Who is online

Users browsing this forum: No registered users