How to add time to the corner of 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
billynoeyes
Newbie
Posts: 18
Joined: Thu May 03, 2018 7:13 am
Contact:

How to add time to the corner of game?

#1 Post by billynoeyes »

Hello,

I have set up a simple time system using python, and it works great. However, I would love if the player could look up at the corner and see the current time. I also plan on adding days and weeks, and it would be great if it displays this too.

Secondly, is there anyway to move menues and text to the left of the screen? I display characters on the right and would prefer if they could maintain visibility during menus and large bits of text.

Thank you!

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to add time to the corner of game?

#2 Post by kivik »

First one is easy, you just need to setup a screen and show it at the start of the game. Here's the documentation on making screens: https://www.renpy.org/doc/html/screens.html

If you have trouble after reading through it, do let us know - although we'll need to know the format of your time variable(s).

Second one is more complicated but absolutely doable. After reading the screens page on the documentation above, check this page out: https://www.renpy.org/doc/html/gui.html particularly this part about dialogue windows: https://www.renpy.org/doc/html/gui.html ... -continued

There's a lot at play here, you'll need to adjust the sizes and alignment of the screens. You can override default styles that are declared in the screen.rpy file - so the best option is just creating your own styles.rpy file and put them in there.

The game menu's probably going to be the hardest to get right due reduced spaces - but I think it's a fluid design so it should fit into whatever size you give it.


Let us know if you need further help after getting started with it.

billynoeyes
Newbie
Posts: 18
Joined: Thu May 03, 2018 7:13 am
Contact:

Re: How to add time to the corner of game?

#3 Post by billynoeyes »

Thanks dude, very helpful stuff. I'll spend a few hours setting it all up and let you know :)

billynoeyes
Newbie
Posts: 18
Joined: Thu May 03, 2018 7:13 am
Contact:

Re: How to add time to the corner of game?

#4 Post by billynoeyes »

Ok so I am having trouble adding my day system.

At the moment, everyday you go to the main menu I have time_points go up by 2. When it reaches 10, you go to sleep. Going to sleep increases day_points by 1, and I've tried to set up a big elif chain wher 1 day_points is monday, 2 tuesday etc.

but I cant seem to define day.

I have name defined using python so that the character name is customizable, and I want to be able to do [day] in my script the same wawy I do [name], but you input [name] by typing, where as I want [day] to change in relation to day_points. Does that make sense? I hope so.

thanks in advance, hers a screenshot.

http://puu.sh/AhdBV/c414725a78.png
http://puu.sh/AhdCV/bba78fb5be.png
http://puu.sh/AhdDm/f00fb50b84.png

the time thing was totally working before I starting messing with days for the record.

billynoeyes
Newbie
Posts: 18
Joined: Thu May 03, 2018 7:13 am
Contact:

Re: How to add time to the corner of game?

#5 Post by billynoeyes »

Ok now I have got the code that it increases teh day to work, and it can add something to day, but it always adds monday.

So when I check what day it is, it always says monday.

What am I doing wrong?

if day_points = 1:
python:
day = "Monday"
elif day_points = 2:
python:
day = "Tuesday"
elif day_points = 3:
python:
day = "Wednesday"
elif day_points = 4:
python:
day = "Thursday"
elif day_points = 5:
python:
day = "Friday"
elif day_points = 6:
python:
day = "Saturday"
elif day_points = 7:
python:
day = "Sunday"
else:
"Day is unkown."

I guess I need an if statement that means only if it is exactly this integer, as at the moment the integer is 5 and it seems happy to use that for monday

billynoeyes
Newbie
Posts: 18
Joined: Thu May 03, 2018 7:13 am
Contact:

Re: How to add time to the corner of game?

#6 Post by billynoeyes »

Ok sorry for all the posts, but I fixed it. I just had to move the code to run after I slept and i before it told you what day it was.
Sorry :s

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to add time to the corner of game?

#7 Post by kivik »

Your way of approaching weekdays won't work because every single day will be caught by day_points >= 1, it'll never pick any of the other conditions. Plus even if you use ==, it won't do what you want it to do after 7 days anyway.

Now I hope you're sitting comfortably because I'm about to teach you about using remainders in divisions to work out day of the week AND the days lapsed since start of game using a single variable :)



First, we'll have a variable call day (you can call it day_points, it's the day number in your game. You'll increment it by 1 every single day, no exceptions. From it, we're going to work out the day of the week:

Here's the math: there're 7 days in the week, so if you divide days by 7 and take the remainder, it'll basically tell you what day of the week it is - as the remainder can never exceed 6 (0-6, which is 7 values). 0-6 may seem annoying, since you may be thinking 1-7 works better, but there's where computer arrays come into play. Arrays always start at 0, so an array size 7 has an index of 0-6 - matching our remainders exactly!

So what do we do with this math? I'll show you! Note: I'm going to make a clock object for ease:

Code: Select all

init python:
    class Clock(object):
        weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
        def __init__(self):
            self.day = 1

        @property
        def weekday(self):
            return Clock.weekdays[self.day%7]

default clock = Clock()

label start:
    "Today is day [clock.day] and it's [clock.weekday]"
So to explain what's going on:
- The Clock object stores the day value, you can reference it by clock.day, you can add to it with clock.day += 1
- The Clock object also has a static variable called weekdays - you may notice that it starts on Sunday, because we don't want to start at Day 0, so I shifted Sunday to be the first day to offset it. If you're happy to start your game at Day 0 (technically it is day 0 when you start), then you can make Monday the first day.
- The weekdays variable is a static list (static variables don't change), so weekdays[0] == "Sunday", weekdays[1] == "Monday, and so on. So our remainder calculation will do exactly what we want!
- clock.weekday is a method / function that returns the static variable Clock.weekday by the index of [remainder when dividing days by 7]. The formula is day % 7
- I used the @property python keyword to make weekday() act like a variable. clock.weekday triggers clock.weekday() - this means we can do "[clock.weekday]" as we can't put functions in Renpy's text interpolation: "[clock.weekday()]"

So that gives you a way of doing your days - I'd recommend you add the time_points into the clock class object, then you can manipulate date time easily. Let us know if you need help with that.

P.S. Your third screenshot shows some strange indentation - label being indented, I don't know what that does but it may mean your code never reaches if time_points >= 10.

P.P.S. Copy and pasting your code here inside [code] tags would be much easier for us to help you, screenshots means we have to switch between tabs, and retype your code instead of being able to copy, paste and edit your code.

Post Reply

Who is online

Users browsing this forum: Google [Bot], henne