Setting amount of days to pass per event

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
richycapy
Regular
Posts: 51
Joined: Mon May 27, 2019 8:53 pm
Organization: EN Productions
Location: Mexico
Contact:

Setting amount of days to pass per event

#1 Post by richycapy » Wed Jan 06, 2021 5:12 pm

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: Select all

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: Select all

$ 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

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Setting amount of days to pass per event

#2 Post by _ticlock_ » Wed Jan 06, 2021 10:04 pm

Hi, richycapy,

I am not sure how optimal is what you are doing. I guess it depends on the whole picture. Anyway, based on your code, event.variabletochange = event.changeto does not change the variable current_story_state, it changes the variable event.variabletochange (event.variabletochange == "current_story_state") to value of event.changeto. To change the variable with name event.variabletochange you can use store.__setattr__(event.variabletochange, event.changeto):

Code: Select all

label sleep_again:
    e "Im going to bed"
    python:
        for event in current_events_ongoing:
            event.daystopass -= 1
            if event.daystopass <= 0:
                store.__setattr__(event.variabletochange, event.changeto)
                current_events_ongoing.remove(event)

Post Reply

Who is online

Users browsing this forum: No registered users