How to force an 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
bdaywans
Newbie
Posts: 15
Joined: Sat Jul 13, 2019 2:54 pm
Contact:

How to force an event

#1 Post by bdaywans » Sun Aug 18, 2019 10:04 am

I didn't think this should be hard but I'm k=having trouble forcing and end of day event. I have a NewDay event which works file when the character selects 'sleep' but I want to also force it so that when the HOUR timer hits a certain number it forces a jump to the NewDay event.

I had a stats file and In there I had:

Code: Select all

default hour = 7
if hour >= 24:
  jump NewDay
At another point in the script I have a crude HUD:

Code: Select all

screen Day:
     text "Day [day]" xpos 0.1 ypos 0.1
     text "Time [hour]" xpos 0.1 ypos 0.15
     text "Money [money]" xpos 0.1 ypos 0.2

I keep trying to get it to end the day but the hour count keeps going past 24

User avatar
Kia
Miko-Class Veteran
Posts: 912
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Skype: KiaAzad
Contact:

Re: How to force an event

#2 Post by Kia » Sun Aug 18, 2019 10:36 am

it all depends where you put this part of the code:

Code: Select all

if hour >= 24:
    jump NewDay
for example if it's in a label that is called every morning, the jump happens the first morning after 24hrs

alternatively, you can put it inside a screen:

Code: Select all

screen timer_ol:
     if hour >= 24:
          timer 0.1 action Jump("NewDay")
for your day HUD, you need to use "If" with your counter

Code: Select all

screen Day:
     timer 1 repeat True action If(hour < 24, SetVariable("hour", hour+1), [SetVariable("hour", 0), SetVariable("day", day+1)])
     text "Day [day]" xpos 0.1 ypos 0.1
     text "Time [hour]" xpos 0.1 ypos 0.15
     text "Money [money]" xpos 0.1 ypos 0.2
note: untested code, might contain errors

User avatar
Remix
Eileen-Class Veteran
Posts: 1456
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to force an event

#3 Post by Remix » Sun Aug 18, 2019 11:45 am

So, where in your script does the hour change?
Are you using a timer like Kia showed or just adding to the variable in a label?

Either way, you'd likely do best concentrating on that point as a place to also run the conditional test to see if it's a new day.
Frameworks & Scriptlets:

bdaywans
Newbie
Posts: 15
Joined: Sat Jul 13, 2019 2:54 pm
Contact:

Re: How to force an event

#4 Post by bdaywans » Mon Aug 19, 2019 8:59 am

Thanks to you both, I think my issues is where I have it... and apparently I'm not sure where it should be. I have a few rpy files - my main script with the events and dialogue options, a navigation script with my locations and where they go, and my stats file for all the variables items and relationships. In the last one, my stats, I start it off by defining things like the day and hour (which I then add to the screen call) and when I define hour I told it "if hour >= 24:"... but throughout the game between the locations and conversations I wanted the user to have more freedom in where they go so they could talk to whoever they want or do certain activities but each one would cost time and energy. If time got to 24 it would start a new day.

So where would it be best to add this? I can add it to the screen like you suggested but anyplace else?

This way if there are other stats that are not displayed but have 'countdowns' to them I'd know where to put them.

bdaywans
Newbie
Posts: 15
Joined: Sat Jul 13, 2019 2:54 pm
Contact:

Re: How to force an event

#5 Post by bdaywans » Mon Aug 19, 2019 10:12 am

Kia wrote:
Sun Aug 18, 2019 10:36 am
it all depends where you put this part of the code:

Code: Select all

if hour >= 24:
    jump NewDay
for example if it's in a label that is called every morning, the jump happens the first morning after 24hrs

alternatively, you can put it inside a screen:

Code: Select all

screen timer_ol:
     if hour >= 24:
          timer 0.1 action Jump("NewDay")
for your day HUD, you need to use "If" with your counter

Code: Select all

screen Day:
     timer 1 repeat True action If(hour < 24, SetVariable("hour", hour+1), [SetVariable("hour", 0), SetVariable("day", day+1)])
     text "Day [day]" xpos 0.1 ypos 0.1
     text "Time [hour]" xpos 0.1 ypos 0.15
     text "Money [money]" xpos 0.1 ypos 0.2
note: untested code, might contain errors
Thanks, I tried your code and it did work. Though one thing that I may have described incorrectly was that I wanted the timer to be more of a 'counter' - the player can do different actions, each adding 1 or two hours to the 'hour' variable. When 'hour' reaches or exceeds 24 the it forces the NewDay jump

Yours worked great except for me it was just adding the hours like a timer, but that said it DID work. Anything I can do to modify it to could the hours as they change vs just counting up?

Post Reply

Who is online

Users browsing this forum: Google [Bot]