Calling the label on all screens

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
oldhiccup
Newbie
Posts: 14
Joined: Thu Jan 28, 2021 8:27 pm
Contact:

Calling the label on all screens

#1 Post by oldhiccup »

I have a variable label, basically these variables control some aspects within my game.

I have a loop that performs an event check, and before the loop I execute the calling of these variables, however during the game, I need to create new variables and find that I have to restart the whole game so that my variable is defined, or call the label at the beginning of my new script file.


To avoid having to call this, I put my variable variable inside my loop but even so it doesn't work, how do I make the variable available to me at any time during development, without having to call it again?

Code: Select all

label variables:
    $ varA = 0
    $ varB = 1
    return

label loop:
    while runing:
        call variables
        call event
    return

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Calling the label on all screens

#2 Post by gas »

oldhiccup wrote: Wed Feb 17, 2021 12:23 pm I have a variable label, basically these variables control some aspects within my game.

I have a loop that performs an event check, and before the loop I execute the calling of these variables, however during the game, I need to create new variables and find that I have to restart the whole game so that my variable is defined, or call the label at the beginning of my new script file.


To avoid having to call this, I put my variable variable inside my loop but even so it doesn't work, how do I make the variable available to me at any time during development, without having to call it again?

Code: Select all

label variables:
    $ varA = 0
    $ varB = 1
    return

label loop:
    while runing:
        call variables
        call event
    return
You're a bit confused about coding in renpy/python.
Obviously if you add a new variable, the game will know of it only at re-running of it. Is not retroactive (and believe me: there's no coding that work fine retroactively).

ANYWAY, and read carefully: if you save the game with a code so made, the whole thing implode.
Variables that should be pickled, as ones that determine a flux control, should be declared as default.
Read the docs where it does explain default variable declarement (the one you're not using and you should), that will hint you why you had to call the variables label at the start of the game (and maybe try to understand the INIT phase).
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Calling the label on all screens

#3 Post by zmook »

The code you provided looks like it should work. There are lots of reasons a variable might be out of scope when you try to use it, though, and I can't guess from this which problem you might have. Can you post more of your real code that has the problem?
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: No registered users