Help find or make SIMPLE, non-linear methodology to manage game states: dialog,combat,navigation,plot flag? (ongoing)

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:

Help find or make SIMPLE, non-linear methodology to manage game states: dialog,combat,navigation,plot flag? (ongoing)

#1 Post by henvu50 »

Anyone feel like sharing or helping me make a basic methodology to handle non-linear Ren'py gameplay, in regards to managing game states: Dialog, Combat, Navigation, Plot flags?

I'm looking for theory & methodology, a basic structure, example:

Code: Select all

file: script.rpy

# a centralized point of origin for the entire game, where the entire game is managed in a simple and efficient way: handles dialog, combat, navigation, plot flags.

# is player in dialog, combat, or navigation?
default game_currentState = "dialog" 
# plot flags ... how do we manage these? when do we check for these? If not handled properly, this can turn into a complete nightmare of code.

label start:

if game_currentState = "dialog":
   if plotflag1 = true:
       ????
   if plotflag2 = true:

if game_currentState = "combat":
   if plotflag1 = true:
      ???
   if plotflag2 = true:
if game_currentState = "navigation":
   if plotflag1 = true:
       ??? then these areas are enabled
   if plotflag2 = true:
       then add these new areas

I'm trying to avoid dissecting existing projects. I 'm looking for a simple structure of renpy code.

I'm not looking for a general diagram of game state you can find on the web, but rather a structure that's already been made in Renpy for non-linear gameplay.
Last edited by henvu50 on Sat Jun 12, 2021 10:54 pm, edited 1 time in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Help find or make SIMPLE, non-linear methodology to manage game states: dialog,combat,navigation,plot flag?

#2 Post by Imperf3kt »

There are many ways to handle this, and no one size fits all method.
Whatever you do will need to be highly customised to suit your game so you won't find any pre-existing code or structure.

Have a read through this to get some ideas.
https://www.renpy.org/doc/html/label.html
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

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

Re: Help find or make SIMPLE, non-linear methodology to manage game states: dialog,combat,navigation,plot flag?

#3 Post by henvu50 »

Imperf3kt wrote: Wed Jun 09, 2021 10:36 pm There are many ways to handle this, and no one size fits all method.
Whatever you do will need to be highly customised to suit your game so you won't find any pre-existing code or structure.

Have a read through this to get some ideas.
https://www.renpy.org/doc/html/label.html
I'm sorry, is that the right link? Nothing in that link talks about bare bones methodology to organize game state, bringing together multiple systems, guided by a plot flag system, all in a manner that's basic & efficient, to eliminate a future nightmare of chaotic code.

Hear me out. I'm looking through the code of existing ren'py games, starting from label start. They are a complete and total nightmare of disorganization. I've yet to find one ren'py game whose code isn't a complete cluster of chaotic madness. I know it exists, I just need to find that one guy who truly knows what he's doing when making organized structures.

I truly believe there is an optimal, bare bones structure for:
- linear approach;
- non-linear approach; This is what I'm interested in.

I'm talking about a rudimentary, highly efficient, basic skeletal structure.

Here's another example to spark the creative juices:

Code: Select all


label start:

    # in the end, even though the game has non-linear aspects, it's still ultimately linear, but with branches, unique choices, areas that may or may never unlock
    call characterCreation
    call prologue 
    call actone
    call acttwo
    call actthree
    call credits
    
    #i've seen people put 100's of lines of code here, that is insane. a methodology is needed to avoid that.

label prologue:

    #load prologue map data into modular navigation code; navigation system is generic and can receive any custom data unique to each map
    #begin events
    call prologue_event01
       # prologue_event01 is made up of npcEncounter01, npcEncounter02, etc
    call prologue_event02
       # what plot flags were set in prologue_event01?
       # things can start to get confusing at this point, an organized methodology can avoid this
    call prologue_eventFinal

label actone

    # load map data into modular navigation code
    # check flags set from prologue
    # best way to contain quests for maximum organization and zero headache?
    # best basic skeletal structure to bring quests & plot flag checks together with the least amount of code?
    
    # what modular, bare bone systems exist for renpy for linear & non-linear types of games? 
    # Ren'py has been in development for 16 years. 
    # Which methodologies are the most prevalent among ren'py projects since its inception for non-linear game design?[/u][/b]

None of the above is in this link: https://www.renpy.org/doc/html/label.html
Imperf3kt wrote: Wed Jun 09, 2021 10:36 pm There are many ways to handle this, and no one size fits all method.
If you go over every single ren'py game ever made since 2004, you would eventually begin to see patterns, all leading to a few basic, highly organized structures. I'm looking for those structures.

They're super basic structures too. Like an outline for a story.

From what I'm seeing in most ren'py games, everyone is re-inventing the wheel, OVER & OVER & OVER AGAIN. That' crazy, lol.

Here's an example of what I'm googling:

renpy event plot flag quest management
renpy non linear methodology
renpy game state management framework
renpy game theory open world management bare bones framework

Here's an example of one: https://github.com/paktek123/raiser_rpg_framework
- Look at the label start there, looks organized. Seems clean.

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

Re: Help find or make SIMPLE, non-linear methodology to manage game states: dialog,combat,navigation,plot flag?

#4 Post by henvu50 »

Okay let's make a list of Ren'py design styles:

This is what I've seen so far. Most renpy games fall into one of these categories. There might be more styles I'm unaware of. If someone wants to add more, please do.

- By day

Code: Select all

label start:
    call characterCreation
    call dayOne
    call dayTwo
    call dayThree
    call dayFour #end of game
- By Story Outline (not feeling this approach, because actTwo & actThree would share the same core systems,

Code: Select all

label start:
     call characterCreation
     call prologue
     call actOne
     call actTwo # made of many core systems
     call actThree # not sure if this should be separate....I'm not liking this story outline approach
- By Areas, Major Plot Flags checked on each Area_Enter event, stored in global_plot_flags.rpy (This seems best for non-linear design)

Code: Select all

label start:
    call characterCreation
    call startingArea # record plot flags from decisions made  # can call this prologue, finishes fast
    call mainGameArea # main game, made up of sub areas. upon every area_enter event, check global_plot_flags, and alter area state accordingly
    # quests direct player to npc or interactable object that alters state between: combat, navigation or dialogue.
    # do all areas invoke a universal global plot flag check?  
    # what is best system to bring plot flag checking, area transition, npc discussion, all together into something organized and easy to maintain code wise?
- By major plot flags

Code: Select all

label start:
    if plotFlag01
       alter state
         setArea("starter")??
         setNavigationMap("starter")?? # places you can and can't go based on plotflag
         setNPC("starter")??
    if plotFlag02
       alter state
    if plotFlag03
       alter state;
         goto 
I'm looking for organizational stuff like this.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Help find or make SIMPLE, non-linear methodology to manage game states: dialog,combat,navigation,plot flag?

#5 Post by Imperf3kt »

I know there were no examples of what you were after specifically within the link, I shared it to show exactly that and the rest of the info should have shown that that's just how renpy works.
The closest thing might be global and local labels.


The best answer I can give is to structure your game within multiple.rpy files and use label and control flow to loop, call and jump around as needed.
Other than that, you've answered your own question as far as I can see.

What kind of game are you attempting to make? You can find some frameworks like the dating sim engine or the RPG overworld engine etc in the cookbook, or are you after some other structure?


Of course, I may not be the best person to talk with about this, as I have limited experience with it beyond the simplest of games and the tutorial (that's a confusing mess, sorry PyTom)

My signature has links to a couple of projects where you can see how I like to organise and structure my code. Feel free to criticise.
Note that both are still a WIP, and that only the blackjack game currently has sufficient comments. When finished, sections of relevant code will be moved to separate.rpy files.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

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

Re: Help find or make SIMPLE, non-linear methodology to manage game states: dialog,combat,navigation,plot flag?

#6 Post by henvu50 »

Imperf3kt wrote: Thu Jun 10, 2021 12:32 am What kind of game are you attempting to make? You can find some frameworks like the dating sim engine or the RPG overworld engine etc in the cookbook, or are you after some other structure?
Open world, moving from area to area. With major plots flags that get set as the player progresses. Each area undergoes different changes based upon plot flags.

I'm just trying to figure out the basic framework, at the most rudimentary level. Your original ink you gave me is definitely the major element. I was just hoping there was a tried and true methodology. A bare bones framework that would cut a few days of development time. I'm trying to avoid doing what I'm doing now.

I've checked out the other frameworks and didn't like it. My search will most likely continue for days until I find that perfect clean structure.

I think this is what I'm gonna go with. Doesn't something like this seem the most efficient to you, for non-linear? If you're busy no need to respond! Don't want to take up your time. Just thinking out loud.

New game.. (note: this is all theory, not to actually be copy & pasted and used.. just scribblings of theory)

Code: Select all

 
script.rpy

default currentArea = "starter" 

default plotFlag01Complete = false
default plotFlag02Complete = false
default plotFlag03Complete = false

label start:
    #setup stuff 
    # character creation
    # warnings if needed
    # introduction
    jump loop_plotFlagCheck

#jump to this label after setting a major plot flag to true. If the last plot flag is true, then roll credits because it's the end of the game.
label loop_plotFlagCheck:

    if plotFlag01Complete = false # game has begun
        jump to starterArea:
           starter area: 
           # has it's own map
           # player moves from subarea to subarea using a modular navigation framework that receives custom map data
           # every time player moves:  subarea_onEnterEvent - check subPlotFlags ?? does an auto triggered event take place?
           # every time player clicks on npc: npc_OnBeginDialogue - check subplotFlags ?? does an auto triggered event take place?
           # every time player clicks an object like a wrench: miscObject_onClicked - check subplotFlags ?? does an auto triggered event take place?
           # starterArea.rpy has it's own subPlotFlags. Once all are set to true, set plotFlag01Complete=true,
               # does this mean starterArea requires it's own loop_subPlotFlagCheck_StarterArea?
           # then Jump back to loop_plotFlagCheck .... which moves onto the PlotFlag02Complete line check
    if plotFlag02Complete = false # prologue is finished, the main part of game begins?
          jump to main area:
             main area: # much like the starter area, just with new map data, more npc's, & objects.
    if plotFlag99 = true
        roll credits
        jump out of this loop, end the loop.. return or jump out?

    jump loop_start
    
Last edited by henvu50 on Thu Jun 10, 2021 1:42 am, edited 1 time in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Help find or make SIMPLE, non-linear methodology to manage game states: dialog,combat,navigation,plot flag?

#7 Post by Imperf3kt »

Of course. The problem is, such a structure is a lot of work (as you've noted) and the people who do the work necessary, tend to charge money for their game and not share its code structure.


You could try asking on the discord, you're likely to find someone more knowledgeable than myself who may help.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Help find or make SIMPLE, non-linear methodology to manage game states: dialog,combat,navigation,plot flag?

#8 Post by zmook »

henvu50 wrote: Thu Jun 10, 2021 1:08 am I'm just trying to figure out the basic framework, at the most rudimentary level. Your original ink you gave me is definitely the major element. I was just hoping there was a tried and true methodology. A bare bones framework that would cut a few days of development time. I'm trying to avoid doing what I'm doing now.
Something like this? This is for a game structured primarily as a pile of "quests" or chains of events. Like, once you have discovered the sea cave, then the Cave Chain becomes available.

I wouldn't call it "tried and true" -- the majority of Renpy games seem to be written by artists, not engineers, and end up as piles of spaghetti. And my own game is a pile of ideas more than anything playable at this point.

The Design Patterns of Ren'py has not been written, I don't think. Some of the classic Design Patterns definitely do apply, like Dispatcher and State. Summertime Saga is perhaps the best example of a game I've seen that implements a formal State Machine internally.

Code: Select all

# The game starts here.
label start:
    $ renpy.log('Starting with logging')

    call initialize_quests
    show screen status_UI()
    
    jump core_loop
    
label core_loop:
    
    $ scene_queue, current_activities = track_time_passing(clock, scene_queue)
    
    call scene_chooser from _call_scene_chooser
    $ scene_label, scene_event  = _return
        
    call expression scene_label from _call_expression
    if scene_event:
        $ scene_event.has_happened = True
    
    jump core_loop # start over

Code: Select all

init python:
    
    def check_quest_events(clock, scene_queue):
        """Update scene_queue; rebuild current_activities from scratch.
        Scenes can be inserted from other mechanisms, such as mandatory sleep.
        """
        global all_quests
        
        current_activities = []
        for q in all_quests:
            for e in q.events:
                if e.is_due(clock):
                    if e.activity:
                        current_activities.append(e.activity)
                    else:
                        label = e.scene_label
                        if not label in scene_queue:
                            scene_queue.append(label)
        
        return scene_queue, current_activities
    
    
    def track_time_passing(clock, scene_queue):
        
        global awake_since
        renpy.log('time controller: clock=%d' % clock)
        
        manage_upkeep()
        
        scene_queue, current_activities = check_quest_events(clock, scene_queue)
        
        if clock - awake_since > exhaustion_hours:
            scene_queue.append("involuntary_sleep")
        
        return scene_queue, current_activities
        

Code: Select all

label scene_chooser():

    python:
        next_scene = "error"
        if scene_queue:
            next_scene = scene_queue.pop(0)
        else:
            next_scene = "map"
        next_event = Event.by_label(next_scene)   # may be None
    
    return next_scene, next_event
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: Google [Bot], henne