Main Loop part 4: Work

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 work. Two arrival messages are offered, one for arrival with everyone else, and one for other times. In both cases pcLoc is set to workPer.

loc/workPer.rpy

    #
    # Player's work.
    # Date/Period style.
    #
label workPer:

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

    # Player arrives at work from somewhere else.
    #
label .arrive:
    $ dbgLabel('workPer', 'arrive')
    if period == 1:
        "Like ants returning to the nest you and your co-workers file in
        through the revolving doors, and scan your keycards at the barriers.
        Same old same old."
    else:
        "The revolving doors usher you into to the office building, then you
        scan your keycard at the barrier before taking the elevator up to your
        floor, and your cubicle."
    $ pcLoc = 'workPer'
    return

Choice

For the moment the work place only has three options: to have lunch at lunchtime, to do some work, and to go home.

loc/workPer.rpy (cont)

    # Offer player a choice of what to do.
    #
label .choice:
    $ dbgLabel('workPer', 'choice')
    menu:
        "{alt}Menu. {/alt}What to do?"
        "Lunch" if period == 2:
            call .lunch from work_per_choice_lunch
        "Work":
            call .work from work_per_choice_work
        "Go home":
            call .goHome from work_per_choice_home
    return

Travel To

The travel options are limited to going home or going to town (though town is not an option offered in the choice menu yet). Both of these walk the player back into town. In the case of going home the town's travel to will take over and get the player character on the bus home.)

The works canteen could be made a separate location and this might make sense if you wanted to offer the player other choices there. It is part of the flexibility of this approach. For the time being though the canteen is kept simple.

loc/workPer.rpy (cont)

    # Have the player travel to a new location.
    #
label .travelTo:
    $ dbgLabel('workPer', 'travelTo', 'destLoc={}', destLoc)
    if destLoc in ('homePer', 'townPer'):
        "You walk back into the centre of town."
        $ pcLoc = 'townPer'
    else:
        # Fall back if there's no specific travel message.
        "You leave work and head to your destination."
        $ pcLoc = destLoc
    return

Activities

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

Go home

Other than checking that they've done some work (which would be better with a flag than testing period like this), this is the same as the other go somewhere examples.

loc/workPer.rpy (cont)

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

    # Player character wants to go home.
    #
label .goHome:
    $ dbgLabel('workPer', 'goHome')
    if period == 1:
        "It really is too early to be going home. You haven't done any work yet!"
        return
    call mainPer.travelTo('homePer') from work_per_go_home_travel
    return

Go into town

This isn't used, but shows how to travel into town from work.

loc/workPer.rpy (cont)

    # Player character wants to the town.
    #
label .goTown:
    $ dbgLabel('workPer', 'goTown')
    if period == 1:
        "It really is too early to be leaving. You haven't done any work yet!"
        return
    call mainPer.travelTo('townPer') from work_per_go_town_travel
    return

Lunch

This outline for lunch is trivial and could be a lot more interesting!

loc/workPer.rpy (cont)

    # Player character wants to eat in the staff canteen.
    #
label .lunch:
    $ dbgLabel('workPer', 'lunch')
    "The staff canteen offers a reasonably priced lunch."
    $ addPeriod()
    return

Work

Work is going to use player character energy so that is checked first. It also needs to be not too late. If they do work burn energy, add money, and use a time period.

loc/workPer.rpy (cont)

    # Player character does some work.
    #
label .work:
    $ dbgLabel('workPer', 'work')
    if energy < 4:
        "You're too tired to work. You should probably go home."
        return
    if period >= 4:
        "Everyone else has gone home. You probably should too."
        return
    "You settle down at your desk and begin keying in data from form WS2475.
    It's dull work, but it pays the bills."
    $ pcMoney += 80
    $ energy -= 4
    $ addPeriod()
    return

Conclusion

This is the last part of the main loop example. It is just an outline, but I hope it shows the benefit of putting the repetitive tests and travel mechanism in the main loop making it easy to add new locations and player choices.

Other parts of the main loop example