Keeping track of events [SOLVED]

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
User avatar
Wiceramond
Regular
Posts: 25
Joined: Mon Dec 07, 2020 8:40 am
Contact:

Keeping track of events [SOLVED]

#1 Post by Wiceramond »

Let's say I have 3 different variables for controlling if 3 different events are done in the game. If I want to check how many of those done at the end, how do I do that? If there are 50 events I'm tracking it's gonna be really hard to keep track of 50 different variables I guess. I know this is a really simple question but I just couldn't come up with a solution so thanks in advance.

Code: Select all

$ alice_journey_done = False
$ nices_journey_done = False
$ robo_journey_done = False

label alice_journey:
    # Things happened.
    $ alice_journey_done = True
    return

label nices_journey:
    # Things happened.
    $ nices_journey_done = True
    return

label robo_journey:
    # Things happened.
    $ robo_journey_done = True
    return
Last edited by Wiceramond on Sun Feb 28, 2021 11:20 am, edited 1 time in total.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Keeping track of events

#2 Post by _ticlock_ »

Hi, Wiceramond,

These things can be organized using dictionaries. For example,

Code: Select all

default events = {
    "alice_journey" : False
    "nices_journey" : False
    "robo_journey" : False
    }
label alice_journey:
    # Things happened.
    $ events["alice_journey"] = True
    return
Now we can make a function that returns how many events are completed or how many events are completed for a particular character (we can do it, for example, if all events with character alice has "alice" in event name: like "alice_journey", "alice_party".

Code: Select all

init python:
    def event_counter(char_name = ""):
        sum = 0
        for key, value in store.events.items():
            if char_name in key and value != False:
                sum += 1
        return sum
In similar manner we can check for more complex story progress. You can also use numbers in the dictionaries to unite a chain of events.

User avatar
midgethetree
Regular
Posts: 39
Joined: Wed Dec 30, 2020 3:51 pm
Completed: Back When, The Mother of Pearls, various jam games
Projects: When Everyone's Watching, Deliberation
Github: midgethetree
itch: midge-the-tree
Discord: rainafc#3353
Contact:

Re: Keeping track of events

#3 Post by midgethetree »

It would be simpler to use a set, IMO. Example:

Code: Select all

default events = set()
label alice_journey:
    # Things happened.
    $ events.add('alice_journey')
    return
then you can just check the number of events using len(events). You would then also replace checks like "alice_journey_done == True" with " 'alice_journey' in events", if you ever need to check if a specific event has been done.

Post Reply

Who is online

Users browsing this forum: No registered users