Page 1 of 1

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

Posted: Fri Nov 08, 2019 12:37 pm
by thomas_oak
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

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

Posted: Fri Nov 08, 2019 12:47 pm
by isobellesophia
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.

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

Posted: Fri Nov 08, 2019 1:01 pm
by thomas_oak
Thank-you Isobellesophia, but I don't want to check the time variable, I want to manually alter it to a specific time.

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

Posted: Fri Nov 08, 2019 2:02 pm
by papillon
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.

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

Posted: Fri Nov 08, 2019 2:33 pm
by thomas_oak
Hello Papillon.

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

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

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

Posted: Fri Nov 08, 2019 8:30 pm
by papillon
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.

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

Posted: Fri Nov 08, 2019 10:10 pm
by thomas_oak
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

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

Posted: Sat Nov 09, 2019 3:19 pm
by papillon
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.