Ren'Py Setting amount of days to pass per event

RichyCapy

Active Member
Game Developer
Jul 26, 2017
808
909
Greetings to you all,

Im trying to create a simple way to countdown days and change a variable to continue with the story, here is an example, I created this:

Code:
class current_event:
        def __init__(self,  daystopass, variabletochange, changeto):
            self.daystopass = daystopass
            self.variabletochange = variabletochange
            self.changeto = changeto
Then on the story I did this:

Code:
$ current_events_ongoing = []

e "With 3 nights I should be fine"


$ nightsleep  = current_event( 3, "current_story_state", 2)

$ current_events_ongoing.append(nightsleep) 

$ current_story_state = 1

label night_cycle:
            if current_story_state  == 2:
                        e "Im well rested!"
                        jump end_story
            else:
                        e "I need more sleep"
                        jump sleep_again


label sleep_again:
            e "Im going to bed"

python:
            for event in current_events_ongoing:
                        event.daystopass -= 1
                        if event.daystopass <= 0:
                                    event.variabletochange = event.changeto
                                    current_events_ongoing.remove(event)

jump night_cycle


label end_story
            e "Thanks for the sleep"

Basically, what I’m trying to do, is to set a variable after certain number of cycles (or sleep) and I want it to be this way so I can add multiple events at the same time
Script does countdown the days, but it doesn’t change the variable, how can I accomplish this?

Or it there a better way?

Thanks! :D
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,974
16,229
Code:
class current_event:
        def __init__(self,  daystopass, variabletochange, changeto):
            self.daystopass = daystopass
            self.variabletochange = variabletochange
            self.changeto = changeto
[...]
event.variabletochange = event.changeto
current_events_ongoing.remove(event)
[/code]
Basically, what I’m trying to do, is to set a variable after certain number of cycles [...]
Then, putting the value of the changeto attribute as value of the variabletochange attribute is absolutely not the way to do that.
Code:
class current_event:
        def __init__(self,  daystopass, variabletochange, changeto):
            self.daystopass = daystopass
            self.variabletochange = variabletochange
            self.changeto = changeto

        def timePass( self ):
            self.daystopass -= 1
            if self.daystopass == 0:
                setattr( store, self.variabletochange, self.changeto )
           return not self.daystopass

[...]
label sleep_again:
    e "Im going to bed"

    python:
            for event in current_events_ongoing:
                        if event.timePass():
                                current_events_ongoing.remove(event)

    jump night_cycle
 
  • Like
Reactions: Madmanator99