Main Loop part 3: Town

The town location has to implement a number of labels expected by the main loop just as the home location did. This is the third part of the main loop section.
Note: The Per suffix relates to this being the date/period version in my project.

Arrival

The first label is the .arrival one that is called when the player character gets to the town. Here, based on the day of week and time of day the town centre is described and pcLoc is set to townPer.

loc/townPer.rpy

    #
    # Town.
    # Date/Period style.
    #
label townPer:

    # -------------------------------------------------------------------------
    # Interface labels
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    # Player arrives in the town from somewhere else.
    #
label .arrive:
    $ dbgLabel('townPer', 'arrive')
    if period == 0:
        "The town is quiet, nothing is open yet."
    elif period == 1 and isWorkDayPer():
        "The town is busy with people going to work."
    elif period == 4 and isWorkDayPer():
        "The town is busy with people heading home from work."
    elif period < 4:
        "There are people shopping in the town centre."
    else:
        "The town is quieter, people are going to restaurants and bars."
    $ pcLoc = 'townPer'
    return

Choice

For the moment the town only has two options: to go to work or to go home. For the town to be a central hub it will need more adding.

loc/townPer.rpy (cont)

    # Offer player a choice of what to do.
    #
label .choice:
    $ dbgLabel('townPer', 'choice')
    menu:
        "{alt}Menu. {/alt}What to do?"
        "Go to work" if isWorkDayPer():
            call .goWork from town_per_choice_work
        "Go home":
            call .goHome from town_per_choice_home
    return

Travel To

There are two places to travel to: the office which is a short walk, and home which is a bus ride. For the bus ride, the description changes with the time of day and day of week. Waiting at a bus stop might be a good place to introduce an NPC, while that's beyond the scope of this example it's possible with this structure.

loc/townPer.rpy (cont)

    # Have the player travel to a new location.
    #
label .travelTo:
    $ dbgLabel('townPer', 'travelTo', 'destLoc={}', destLoc)
    if destLoc == 'workPer':
        "The office you work in is a short walk from the town centre."
        $ pcLoc = destLoc
    elif destLoc == 'homePer':
        if isLastPeriod():
            "The night bus home doesn't run very frequently and you have to
            wait a while before one shows up."
        elif period == 4 and isWorkDayPer():
            "The bus is packed as you and the other commuters head home."
        else:
            "The bus isn't nearly as busy it is when you commute home.
            It's almost pleasant."
        $ pcLoc = destLoc
    else:
        # Fall back if there's no specific travel message.
        "You head to your destination."
        $ pcLoc = destLoc
    return

Activities

The remainder of the code for this location implements the choices the player can make. These are kept as subroutines for flexibility.

Going home

All the go to town routine has to do is to call mainPer.travelTo('homePer'). This then makes the required calls to describe the player character's travel and their arrival at the destination.

loc/townPer.rpy (cont)

    # -------------------------------------------------------------------------
    # Local activities
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    # Player character wants to go home.
    #
label .goHome:
    $ dbgLabel('townPer', 'goHome')
    call mainPer.travelTo('homePer') from town_per_go_home_travel
    return

Going to work

The go to work routine works in a similar way, though it first checks that it's an appropriate time of day.

loc/townPer.rpy (cont)

    # Player character wants to go to work.
    #
label .goWork:
    $ dbgLabel('townPer', 'goWork')
    if period == 0:
        "It's to early to go to work, the doors won't be open."
        return
    elif period >= 4:
        "It's pointless to go to work, the office will be closed now."
        return
    call mainPer.travelTo('workPer') from town_per_go_work_travel
    return

Other parts of the main loop example