Is there a way to set the python calendar to a specific time mid game

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
thomas_oak
Newbie
Posts: 19
Joined: Thu Oct 24, 2019 11:28 am
Contact:

Is there a way to set the python calendar to a specific time mid game

#1 Post by thomas_oak » Fri Nov 08, 2019 12:37 pm

I was wondering if there is a line of code which could set the python calendar to a specific time. The instance where this would be most useful would be when the player character goes to sleep. So instead of advancing a number of hours, you wake at 8am. Alternatively you could have an option of waiting until sen-set and the game advances to 8pm say

User avatar
isobellesophia
Miko-Class Veteran
Posts: 700
Joined: Mon Jan 07, 2019 2:55 am
Projects: Maddox's Everyday Talk! (13+ Unreal version), Maddox Everyday Talk! (3+ Real-Friendly version)(Upcoming 2020)
Organization: Friendly Teachers series
itch: .......
Location: Philippines, Mindanao
Contact:

Re: Is there a way to set the python calendar to a specific time mid game

#2 Post by isobellesophia » Fri Nov 08, 2019 12:47 pm

You can make it like a if or else with a variable statements to it, alot of people has been victimed for asking these questions..

I cannot give any examples, im so sincerly sorry.
I am a friendly user, please respect and have a good day..


Working on a talking simulation game for everyone, except children.

Maddox Everyday Talk!
Is my very very main project, not contain 13 below.

Main project here viewtopic.php?f=43&t=56564
Image

thomas_oak
Newbie
Posts: 19
Joined: Thu Oct 24, 2019 11:28 am
Contact:

Re: Is there a way to set the python calendar to a specific time mid game

#3 Post by thomas_oak » Fri Nov 08, 2019 1:01 pm

Thank-you Isobellesophia, but I don't want to check the time variable, I want to manually alter it to a specific time.

User avatar
papillon
Arbiter of the Internets
Posts: 4038
Joined: Tue Aug 26, 2003 4:37 am
Completed: lots; see website!
Projects: that magical diary sequel, that vampire-raising game
Organization: Hanako Games
Tumblr: hanakogames
Contact:

Re: Is there a way to set the python calendar to a specific time mid game

#4 Post by papillon » Fri Nov 08, 2019 2:02 pm

What is "the python calendar"?

Any variable can be quite easily manually altered, so I'm not really sure what the question is.

Are you working with a particular piece of out-of-the-box code? It might help to link to it.

thomas_oak
Newbie
Posts: 19
Joined: Thu Oct 24, 2019 11:28 am
Contact:

Re: Is there a way to set the python calendar to a specific time mid game

#5 Post by thomas_oak » Fri Nov 08, 2019 2:33 pm

Hello Papillon.

I have based my calendar on Remix's "scarily simple calendar"

viewtopic.php?f=51&t=51632&p=494708&hil ... me#p494708

User avatar
papillon
Arbiter of the Internets
Posts: 4038
Joined: Tue Aug 26, 2003 4:37 am
Completed: lots; see website!
Projects: that magical diary sequel, that vampire-raising game
Organization: Hanako Games
Tumblr: hanakogames
Contact:

Re: Is there a way to set the python calendar to a specific time mid game

#6 Post by papillon » Fri Nov 08, 2019 8:30 pm

Okay. That's someone's specific code and has nothing to do with python in general (this is why I was very confused by you asking about "the python calendar").

It looks like the entire point of their code is to let you advance time by specific increments. If advancing time by increments is not what you want for your game, you may not have any use for their code in the first place. You could always just have your own time variable that you set manually instead. Depending on your game design, that might make a lot more sense.

If you definitely want to use this code but need a feature for "advance until X time", then the obvious approach is to make a loop where you:

* Increase the time.
* Check to see if the time has reached the target yet.
* Repeat.

Warning: loops can be dangerous if you give them bad data! If you wrote code of:

Code: Select all

$ my_time_variable = 10 // Start by setting the variable to ten
while my_time_variable != 5: // If the variable is not equal to five
    $ my_time_variable += 1 // add one to the variable, then check it again
then this loop would run forever! Because it's already bigger than five, so it'll just keep adding, checking, adding, checking...

(I have no idea what your level of coding experience is so I'm giving slightly weird information, but I figure I shouldn't mention loops without pointing out that infinite loops are totally possible)

So to do this, you need to work out how to check the current hour in the calendar code you're using.

thomas_oak
Newbie
Posts: 19
Joined: Thu Oct 24, 2019 11:28 am
Contact:

Re: Is there a way to set the python calendar to a specific time mid game

#7 Post by thomas_oak » Fri Nov 08, 2019 10:10 pm

Yes you are right, I should have called it the python datetime module
I was hoping that once the clock had been set using the initial "default" date, that it might have been possible to specify a new date or time after the game commences. If this is going to be impossible then either it would need the slightly dangerous iterative method you suggest, or a rather crude one such that when the character sleeps the time is displayed and a menu of different times are shown with a question "How long do you wish to sleep for?"
So if your character needs to be at work at 9 then you have to calculate the time needed before sleeping each time. Not the end of the world but not very elegant.
I have seen games with a "sleep til morning" being used, but have not found anything in the cookbook or elsewhere. Shame.

Thanks again for your help Papillon

User avatar
papillon
Arbiter of the Internets
Posts: 4038
Joined: Tue Aug 26, 2003 4:37 am
Completed: lots; see website!
Projects: that magical diary sequel, that vampire-raising game
Organization: Hanako Games
Tumblr: hanakogames
Contact:

Re: Is there a way to set the python calendar to a specific time mid game

#8 Post by papillon » Sat Nov 09, 2019 3:19 pm

It's possible to specify a new date, but at that point, why are you using someone's code that is entirely designed for moving forward by increments? You could just use your own date variable and set it whenever you wanted. You don't need a GameTime object to have a date. You can set it to anything you want, at any time.

Code: Select all

$my_stored_date = datetime.datetime.strptime("01 Jan 2018", "%d %b %Y" )
To do this all you need to know is the full date that you want to input. In the version above, it's day month year in that format. If you leave any of those parts out, it will screw up.

You could do the same thing to change the stored date inside a GameTime object if you really, really wanted to by changing its stored "_dt" variable. Again, you'll need to have the full correct date to input.

But why do you need the day, month, and year in the first place? Why do you need the hours stored? Are they actually useful to you?

When I've written scheduler-based games, for example, I've never used any features along those lines, or even thought about such things, because I have no use for them. If I'm doing a setup where the character does one activity per day, then all I need is a day variable. In a game where my character does three activities per day, then I need a day and three subdivisions.

Unless I'm specifically assigning things to happen every single hour, what would I need hours for? And if I *am* having things happen every hour, then I definitely need to increment hour by hour rather than skipping ahead.

I don't know what your game design looks like so I don't know what you actually need.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]