Page 1 of 1

How to force an event

Posted: Sun Aug 18, 2019 10:04 am
by bdaywans
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

Re: How to force an event

Posted: Sun Aug 18, 2019 10:36 am
by Kia
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

Re: How to force an event

Posted: Sun Aug 18, 2019 11:45 am
by Remix
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.

Re: How to force an event

Posted: Mon Aug 19, 2019 8:59 am
by bdaywans
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.

Re: How to force an event

Posted: Mon Aug 19, 2019 10:12 am
by bdaywans
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?