Constant

« Back to Glossary Index

Another basic building block of programming. A constant, like a variable, holds a value, such as True or False, but unlike a variable, the value of a constant should never change during runtime. A constant has a name, which is used to access its value during program execution. In Ren’Py, a constant is declared with define, like define config.game_menu_music = "audio/happy_days.ogg". In this case, the name of the constant is config.game_menu_music and the value is "audio/happy_days.ogg".

Conventionally, most constants in Python use all-caps with underscores separating words like MAX_LEVEL or IN_PHONE_CALL. In Ren’Py, these conventions are sometimes bent for common features like gui and config constants (e.g. define gui.text_color = "#ffffff") or Character definitions (e.g. define x = Character("Xia")).

Notably, Python (and by extension, Ren’Py), do not strictly enforce the rule that a constant cannot change during runtime, however, changing a constant during runtime can cause undefined behaviour (that is, it may appear to do what you want some of the time, but is likely to have unexpected side effects, or may not do what you want at all).

« Back to Glossary Index