Are there some best practices of code organization for Ren'Py?
For now (I'm new in Ren'Py) it seems to be handy to have:
1) one (or several in 2-3 layers if the game is big) of "manager" files containg neigther text nor media content, but just main plot logic: they contain "start" label, keep and change main variable, implement high level forks depending on decisions done in "content" files (see below) and call all other files in corresponding time dependingly on plot logic (jumps use seems very strange and confusing to me, probably because of my previous Java background)
2) content files, each of them covering one part of plot (one dialog, one evening at home, one dream etc) and divided into "logic" section (starting with main file label, ending with "return" and relatively short section where all plot structure is kept: forks, variables changes) and "content" section (containing linear sequences of content, like text, images, sounds, character pictures to show to the user, each sequence starting with a special label that should be called from logic section and ending with "return").
3) service files, defining all game characters, mini-games, effects etc and called probably at the very start of the game.
So far such a systems seems to me clear and easy to use except one detail: if I understood correct, all labels in the game are available globally, so I can't have just label like "ask_where:" but rather something like "day_2_sam_dialog_1_ask_where_is_my_dog:" (that is definitely ugly) to avoid labels duplication despite that labels are mostly used just in one file and have no need to be accessible outside of it.
I suspect that I just see and do something wrong here, but what? Are there some locally available labels or something? Or should the game code be organized different to avoid this problem ando another ones I did not face yet? What kind of Ren'Py code organization is considered by the community around it to be really good?
Code organization: what's wrong and how to improve?
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.
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.
Re: Code organization: what's wrong and how to improve?
If I get you right https://www.python.org/dev/peps/pep-0008/
Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18
Sawa - a game of the Drow Nation
Honest Critique
Poses in visual novels, or how to hold a character properly in the frame
Help save articles to the webarchive. [/color]
Sawa - a game of the Drow Nation
Honest Critique
Poses in visual novels, or how to hold a character properly in the frame
Help save articles to the webarchive. [/color]
- ComputerArt.Club
- Veteran
- Posts: 427
- Joined: Mon May 22, 2017 8:12 am
- Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
- Location: Taiwan
- Contact:
Re: Code organization: what's wrong and how to improve?
You could use the 'call' command instead of 'jump' to solve your problem related to:
"day_2_sam_dialog_1_ask_where_is_my_dog:"
Make it generic, e.g. walkdog
You can add some if statements to vary the content depending on how many times you've done it or whatever.
'Call' will return you to your previous position afterwards, 'jump' will play whatever label is under walkdog.
Organization can be done in whatever way suits your needs.
You can have local labels inside labels, check the docs. I use them but no time to explain any more right now.
"day_2_sam_dialog_1_ask_where_is_my_dog:"
Make it generic, e.g. walkdog
You can add some if statements to vary the content depending on how many times you've done it or whatever.
'Call' will return you to your previous position afterwards, 'jump' will play whatever label is under walkdog.
Organization can be done in whatever way suits your needs.
You can have local labels inside labels, check the docs. I use them but no time to explain any more right now.
Facebook:
Renpy Creators and Enthusiasts Facebook Group
My latest game:
Famous Fables: Read, Learn and Play - Android App for teaching children to read
Creative Commons stuff:
Shape transitions,
100+ 360° photos of Japan,
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Code organization: what's wrong and how to improve?
There are local and global labels, though please note that variables within local labels are still global
Imagine, very basically, you opted to have one file per character, bob.rpy and sid.rpy...with each holding labels named act_NN
Imagine, very basically, you opted to have one file per character, bob.rpy and sid.rpy...with each holding labels named act_NN
Code: Select all
## bob.rpy
# this defines the global label name
label bob:
"Nothing here"
# note the . (dot/period) making this local to bob
label .act_1:
"... no global referenced, so uses its own ( effectively bob.act_2 )"
jump .act_2
label .act_2:
"... now uses global reference from other file to jump there... "
jump sid.act_5
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: Code organization: what's wrong and how to improve?
Thanks for all the answers! Seems that local labels are exactly what I need; too bad I haven't learnt about them by myself.
Who is online
Users browsing this forum: Google [Bot]