Define vs default?

Jon_Sleeper

Member
Nov 14, 2018
284
364
Based on what I know, define is used to declare a constant and is initialised during startup and cannot be changed later on (you could but it would create issues at least what's stated in docs) but default is used to declare variables and it can be changed later on during runtime. Apart from these, are there any other differences between them?
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,486
7,007
You're basically correct.

"define" runs during the "init" phase of Ren'py startup, even if you don't explicitly include the define inside an "init" block. The "init" phase happens before the "load" phase when someone loads a save. Variables declared with "define" will not be included in a game save. Thus, if you change them during game play, they will be reset back to their original values if the player loads a save. That's the main issue you run into if you change them.

"default" does two things. First, it creates the variable in such a way that its value (even after being changed) will be included when the game is saved. More importantly, if you create a save with version 1 of a game that doesn't declare a particular variable and then load it into version 2 of the game that declares the variable with "default", the variable will end up being defined with the default value you specify. Thus, "default" is the safe way to add new variables to an updated version of your game. Basically, the load logic says "is that variable defined in the save file? If so, use the value there. Otherwise, set the value to the default"
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,172
Apart from these, are there any other differences between them?
You can find more on the , especially .


Edit: @Rich answered while I was adding something to the linked thread, so I only keep the link.
 
  • Like
Reactions: Rich

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,172
@anne O'nymous damn thanks man, that thread needs to be pinned
Don't want to make ads for myself, but while you're talking about variables and threads that should be more visible, you probably also should take a look at this regarding variables and save compatibility. After the reading of both, you should know everything that you really need about variables in Ren'py.
 
  • Like
Reactions: Rich

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,486
7,007
@anne O'nymous may not want to self-promote, but is without doubt our resident Ren'py expert...