Games with well organized code?

Forgeshield

Member
Aug 5, 2016
367
412
I learn best by reading code so I've started delving into some Ren'Py games in an attempt to learn good ways to organize them (characters, locations, quests, events, etc).

Any coders among us know of any specific games where the code is setup well? I'm currently looking at SuperPowered and SummertimeSaga because they have more interesting UIs than standard visual novels, and I'm interested in seeing how they handle those extra persistent UI elements.

I've been coding for years, so complexity isn't a problem.
 

Sam

Sysadmin
Staff member
Administrator
Dec 22, 2016
2,507
16,842
The Summertime Saga codebase is going through quite a big refactoring for 0.13
 

Forgeshield

Member
Aug 5, 2016
367
412
The Summertime Saga codebase is going through quite a big refactoring for 0.13
Their code has a ton of huge if/else blocks, so I can see why.

MrDots and the DMD team, have it down to a science.
Thanks, I'll check DMD out.

--------------
I just found that LabRats actually comes with the rpy files, and seems to be well commented. Don't know if it makes any sense yet, but comments are a good sign.
 
  • Like
Reactions: toolkitxx

muttdoggy

Dogerator
Staff member
Moderator
Aug 6, 2016
7,793
43,453
The only errors in Lab Rats that I've noticed are from misspellings.
 

RobJoy

Active Member
Jul 4, 2017
979
654
I learn best by reading code so I've started delving into some Ren'Py games in an attempt to learn good ways to organize them (characters, locations, quests, events, etc).

Any coders among us know of any specific games where the code is setup well? I'm currently looking at SuperPowered and SummertimeSaga because they have more interesting UIs than standard visual novels, and I'm interested in seeing how they handle those extra persistent UI elements.

I've been coding for years, so complexity isn't a problem.
Start learning Python.
 

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,648
28,391
Hmmm, I've only poked around in the code for a few games.

If you want to see a number of variable interactions in action, Lab Rats isn't a bad place to start. Vren at least tries to keep things somewhat organized (pics, etc. declared at the beginning, using labels to break up time perods at each locations, etc.), although some of his screens are handled in script.rpy instead of screens.rpy. At least that was the case in 0.3... There are some fairly intricate variable interactions going on in Lab Rats.

DMD is a fairly straightforward example code-wise, although it breaks things up a lot, with script sections handled by day in separate files. Depending on the structure of your story, this may or may not be useful to you.

The best thing you can do is 'not buck the system'. 'The Choice' (included with the RenPy SDK) gives you a basic starting point, and it's not a bad one. While I think that RenPy over-compartmentalizes things at times (thinking of some of the variable/style declarations here), it's good to take the time to understand how the RenPy developers have broken things up, so that you can make a more informed decision as to what will work best for you.

If you are developing games 'on the fly', it's hard to know all of the variables and such you'll eventually want to use right out of the gate. For your sanity, however, it's best to do some initial/default declarations at the beginning of the script (or in a separate 'variables' file as done in D.M.D.), so that you can find the list of variables you are using easily. You can break these up easily enough by day, etc. with a simple comment. Using the comment out (#) tag is a great way to make notes about something you are doing

Example:
# day 4 variables
$ went_to_grocery_store = False

# day 5 variables
$ went_hiking = False
$ acorns = 0
$ amy_intrigue_level = 0 #this tracks how interested Amy is in making the MC's life more difficult

Breaking up sections with labels can make things easier to find, but I'd suggest not going overboard with this. I was just looking at some code recently where the interaction at a location was broken up into 7 different label sections. some of these were simply 'dialogue breaks', and the story always led to the next label. So while this increased the 'letter count' a bit, it wasn't really accomplishing anything. Some of the other labels WERE important, as they were 'jumped to' by choices made during that part of the story.

Using jump excessively may just be making things more complicated when they don't need to be. If you are always 'jumping' to the same point (i.e. no dialogue fork), and are only jumping there once, a

#### Next part of story - going to next store aisle (this is an example, put whatever you need here to give you the mental cue you need to remind yourself what's going on)

to break up the dialogue can be just as useful as a jump, without adding that 'extra step' for RenPy to track.

Breaking up your ingame images into additional subfolders (see DMD) can be useful, but if you have a group of images that you keep re-using in subsequent updates, having those in a bunch of separate folders might be just making your job harder. Sure, there's the initial 'pic declaration list' during init (assuming you declare your pics at the beginning of script.rpy), but it makes sense to put all of your location-related background in the same folder, as opposed to scattering them across a bunch of unrelated folders. You can break these up by location into separate folders, but breaking them up by day may be less useful if you end up re-using them on subsequent days.

Remember, you are organizing things for YOUR sanity, so whatever works best for you in your development cycles is what you are looking for.

---

In short, before you start writing, it's worthwhile to think about YOUR workload, and what will make it easiest for you to write/develop your story. Not all situations will be the same.

It's also very helpful to do a rough 'diagram' of your story in advance using tools like flowcharts, dialogue trees and such, so that you can picture how things are going to shake out in your story in advance. Sure, you'll end up changing a bunch of these forks as you begin writing the details into the story, but this will give you a roadmap at least. This will also hlep highlight some 'signposts' as to how to better organize things.
 

polywog

Forum Fanatic
May 19, 2017
4,062
6,255
DMD is a fairly straightforward example code-wise, although it breaks things up a lot, with script sections handled by day in separate files. Depending on the structure of your story, this may or may not be useful to you.
Base game + day2 + day3...
Base + event1 + event2...
Home + neighbor's house 1 + neighbor's house 2...
Evil lair + downtown scene + uptown scene...
kansas + yellow brick + oz...
lil red + woods + grandmother's house...
compartmentalization works for a lot of stories. Especially for getting a 0.1 out to the public.
In DMD's case each update is a day, but any event, or group of events can be added as an update.
Many story events are one time only, while others need to be revisited constantly. If you can identify the weeds ahead of time, you can keep them separate from the garden.
 
  • Like
Reactions: Forgeshield

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,648
28,391
The nice thing about a 'day by day' release model is that, once you've written the script for a given day, you won't have to revisit 99% of it. You simply just put a 'to be continued' at the end of your labels for that day, and change that out to 'jump to next day' when you do your next update. This way, you can break up script.rpy into a separate file for each day. See Dating My Daughter for an example of this.

This also makes patching a bit easier, in that you won't need to keep re-downloading the folders for the previous days using a patch framework, and the script files (script.rpy) are comparatively tiny to begin with - the images are where most of the added Mb's come from. Of course, most people like to encrypt their games, so you'd need to figure out how exactly to do a 'patch' in this case. This becomes important for the larger games - I think it's a bit rude to ask people to do a 3 GB download each time you update, but this may require some research as to how to do a patch for an encrypted copy.

Patching encrypted copies is beyond my skillset currently. Others who may know how that works can explain the process for that (i.e. how you make such patches, not how you install them) if they want. The OP was looking for examples and tips r.e. good organization, so I'll limit my own comments to that.
 
Aug 5, 2016
23
40
has some interesting mini games, especially the drag&drop one. But don't learn from their code, learn from their ideas. Drag&drop is trivial in other engines (I only know Unity and UE4 as other engines, though), but in Ren'Py?
Maybe you'll learn something here, even if it's not common conventions and program architecture.
 
  • Like
Reactions: toolkitxx