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.
-
Wiceramond
- Newbie
- Posts: 23
- Joined: Mon Dec 07, 2020 8:40 am
-
Contact:
#1
Post
by Wiceramond » Fri Jan 29, 2021 10:12 am
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.
-
_ticlock_
- Veteran
- Posts: 391
- Joined: Mon Oct 26, 2020 5:41 pm
-
Contact:
#2
Post
by _ticlock_ » Fri Jan 29, 2021 1:40 pm
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.
-
midgethetree
- Regular
- Posts: 39
- Joined: Wed Dec 30, 2020 3:51 pm
- Completed: Appetité Amor, The Mother of Pearls, Anise Flowers, Sinless: on Middle Ground, Back When, I'm Just Here to Change the Lights, DUFE: Masquerade
- Projects: When Everyone's Watching
- Github: midgethetree
- itch: midge-the-tree
- Discord: rainafc#3353
-
Contact:
#3
Post
by midgethetree » Fri Jan 29, 2021 2:54 pm
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.
Users browsing this forum: Ocelot