Use "default" to declare variables before label "start" ?

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
tcassat
Regular
Posts: 30
Joined: Tue Oct 03, 2017 7:32 pm
Contact:

Use "default" to declare variables before label "start" ?

#1 Post by tcassat » Sat Nov 11, 2017 6:06 pm

Hi.

I read something about this, but I don't get it.

In my game, I declare all variables right after the label start: obviously, this causes the inconvenience that every time I add a new variable, I need to start the game again since the old saves will be broken.

From what I read, I can declare these variables in the script before the "label start" using the "default". However, I read some comments saying that declaring all variables before the game starts is not a good practice (???).

My question is simple: can I declare all variables using Default at the beginning of the script? Can this cause some problem with rollback or stuff like that?

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: Use "default" to declare variables before label "start" ?

#2 Post by wyverngem » Sat Nov 11, 2017 10:04 pm

You can even put all default variables in it's own rpy. It won't hurt it. You need to define them before you use them, so default is fine. You could also put them in an init block before the start label like this.

Code: Select all

default name = "Reina"

init:
    $ MeetSarah = False
    $ kissedSarah = False

label start:
    "My name is [name]. Who are you?"
    if name == "Barbara":
        "You won't see this option becuase her default is Reina and I didn't write before this line to change her name with a variable."
    else:
        "Umm...that's not the name of the list. She's [name]. Do you want to be Barbara?"
        menu:
            "Yes":
                $ name = "Barbara"
                jump start
            "No":
                "You're loss."
return

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Use "default" to declare variables before label "start" ?

#3 Post by trooper6 » Sun Nov 12, 2017 4:12 am

Current best practices is to declare your variables outside of any block using default. This will ensure you will be fine with saving and rollback.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

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

Re: Use "default" to declare variables before label "start" ?

#4 Post by IrinaLazareva » Sun Nov 12, 2017 4:47 am

tcassat wrote:
Sat Nov 11, 2017 6:06 pm
However, I read some comments saying that declaring all variables before the game starts is not a good practice (???).
It is true..was true for old versions of renpy.

Post Reply

Who is online

Users browsing this forum: Google [Bot]