Doing updates in turn based games?

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
Deimos96
Regular
Posts: 26
Joined: Tue Nov 15, 2022 5:34 am
Contact:

Doing updates in turn based games?

#1 Post by Deimos96 »

Hello, I'm confused about implementing an "end_day" method that will update all the statuses of my game characters.

To elaborate, I have two classes: Character and Time. In my Character class I have a method called attend_class. To summarize, in that method, the character updates its class quota by +1 until the requirements for passing the class is reached. For example: math class requires 20 quotas to pass, thus the characters must attend that class 20 times. But in my case the Character updates its quota instantly.

I'm looking to implement an end_day method in my Time class that updates that quota only if the day is passed.

So instead of:
attend_class -> +quota -> check if meets required quotas -> pass class
I'm trying to achieve:
attend_class -> end_day -> +quota -> check if meets required quotas -> pass class

Any suggestions? Thanks a lot!

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

Re: Doing updates in turn based games?

#2 Post by _ticlock_ »

Deimos96 wrote: Fri Dec 09, 2022 9:03 am I'm trying to achieve:
attend_class -> end_day -> +quota -> check if meets required quotas -> pass class

Any suggestions? Thanks a lot!
I am not sure if I got you right. You can add a variable that would store changes that you apply later: For example:

Code: Select all

def attend_class(...):
    self.quota_plus += 1

Code: Select all

def end_day(...):
   for c in characters:
       c.quota += c.quota_plus
       c.quota_plus = 0
       # check if meets required quotas -> pass class
if pass class should be done separately and processed latter, again you can add a variable for that:

Code: Select all

    # check if meets required quotas
    if requirements_are_met:
        c.pass_class = True
If you have a lot of variables that you would like to update at the end of the day you may consider having some variable that would store names of stats to update and changes:

Code: Select all

    #save the value and name of variable to update
    self.update.append(["quota", 1])

Code: Select all

def end_day(...):
   for c in characters:
       for stat_name, change in c.update
           setattr(c, stat_name, getattr(c,stat_name) + change)
       c.update = []

Deimos96
Regular
Posts: 26
Joined: Tue Nov 15, 2022 5:34 am
Contact:

Re: Doing updates in turn based games?

#3 Post by Deimos96 »

_ticlock_ wrote: Fri Dec 09, 2022 12:51 pm I am not sure if I got you right. You can add a variable that would store changes that you apply later: For example:

Code: Select all

def attend_class(...):
    self.quota_plus += 1

Code: Select all

def end_day(...):
   for c in characters:
       c.quota += c.quota_plus
       c.quota_plus = 0
       # check if meets required quotas -> pass class
Thank you for your advice. I think I kind of get the idea. Before updating, I store the updates in a temporary variable that acts as potential to be added after the day has ended. And when the end_day method is called, all the potential gets updated into each of its own real values. If I'm not mistaken.

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

Re: Doing updates in turn based games?

#4 Post by _ticlock_ »

Deimos96 wrote: Fri Dec 09, 2022 9:06 pm Thank you for your advice. I think I kind of get the idea. Before updating, I store the updates in a temporary variable that acts as potential to be added after the day has ended. And when the end_day method is called, all the potential gets updated into each of its own real values. If I'm not mistaken.
The concept is correct. The way you do it can be different.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]