Fixing or replacing a clock that displays in-game play time.

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
User avatar
TheChris
Regular
Posts: 47
Joined: Sat Oct 11, 2014 9:26 pm
Projects: Stickshooter
Deviantart: innocencecanceller
Location: United States
Contact:

Fixing or replacing a clock that displays in-game play time.

#1 Post by TheChris » Mon Oct 13, 2014 10:53 am

I have been trying to insert a clock that displays the player's game play time, like in Katawa Shoujo, but I haven't had much luck. I've currently been trying this at the very start of the game:

$ seconds = 0
$ minutes = 0
$ hours = 0
$ ui.timer(1.0, seconds + 1, repeat=True)

and this in my game menu:

if minutes >= 60:
$ hours += 1
$ minutes -= 60

text "[hours]:[seconds]:[seconds]" xalign 0.5 yalign 0.95 style "metext"

My problem is that the clock never adds 1 to the seconds variable. If someone notices a flaw in my programming or knows of an alternative way to create the clock, I would appreciate a response. I've tried looking at some of the other threads here, but they've had the same problem: the second variable remains stuck at 0.


User avatar
TheChris
Regular
Posts: 47
Joined: Sat Oct 11, 2014 9:26 pm
Projects: Stickshooter
Deviantart: innocencecanceller
Location: United States
Contact:

Re: Fixing or replacing a clock that displays in-game play t

#3 Post by TheChris » Mon Oct 13, 2014 7:39 pm

Thank you, Alex. I had tried to use renpy.get_game_runtime and renpy.clear_game_runtime before, but it didn't work. Thanks to your links, I think I got it working now. Here's what I'm doing:

#screen pause is what I have set as the game menu
screen pause_menu:
tag pause

$ gameseconds = int(renpy.get_game_runtime())
$ seconds = gameseconds % 60
$ gameminutes = int(gameseconds/60)
$ minutes = gameminutes % 60
$ hours = int(minutes/60)

text "Gameplay: [hours]hours, [minutes] minutes, and [seconds] seconds" xalign 0.5 yalign 0.95 style "metext"

label start:
$ seconds = 0
$ minutes = 0
$ hours = 0
$ renpy.clear_game_runtime

Post Reply

Who is online

Users browsing this forum: No registered users