Do lines of code with default/define only execute in order, or do they all get instantiated at once during startup?

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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Do lines of code with default/define only execute in order, or do they all get instantiated at once during startup?

#1 Post by henvu50 »

When I declare a variable like this:

Code: Select all

default test50 = "something"
And stick it at the top of my script. It will get declared as soon as I start the program right?

But what if I do this:

Code: Select all

label mid_game_event_three_hours_into_gameplay:
	default test90 = "hey"
Will the variable test90 only instantiate after I jump to that label, or does test90 get instantiated at the beginning when I run the game?

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: Do lines of code with default/define only execute in order, or do they all get instantiated at once during startup?

#2 Post by henvu50 »

Oh wow, the variables are all instantiated at runtime.

Code: Select all

label start:
     #this line will execute and show the text: 'something', even though the line where the test90variable is instantiated is in a mid game event.
     "[test90variable]"

      jump midgameEvent:

label midgameEvent:
     #this label is jumped to three hours into the game, but the following variable is instantiated at runtime
     default test90variable = "something"
Is there a guide that explains the initialization order of everything?

So far, I understand that:

init python, happens first?
default and define variables, happen second?
label start, happens third?

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

Re: Do lines of code with default/define only execute in order, or do they all get instantiated at once during startup?

#3 Post by Ocelot »

It is right there in the manual:
https://www.renpy.org/doc/html/python.html
In short: init phase happens first, even before main menu is shown. default statements execute right after starting or loading the game if corresponding variable does not exist.
< < insert Rick Cook quote here > >


Post Reply

Who is online

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