Making the "countdown" a trigger (solved)

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
CeleryNinja
Newbie
Posts: 2
Joined: Thu Nov 15, 2007 11:12 pm
Contact:

Making the "countdown" a trigger (solved)

#1 Post by CeleryNinja »

Something I planned for the project I'm working on is to make a dialog dependent on the background music.
The way I planned to do it was initiate a countdown, or some other timer, and have it trigger an event when that timer reaches the same time in the song.
The product I'd want is something like this:
(Scene begins)
Ciel: "Ah! I know this song!"
(And then depending on whether or not the player advanced to the next dialog box in time--)
(For example, the timer is in the range of the song's beginning and the "best part")
Ciel: "The best part is coming up!"
(When the timer is equal to the "best part")
Ciel: "Isn't it wonderful?"
(Then continues normally)

(Or if the player advanced to the next dialog box when the timer is in the range between the "best part" and the end)
Ciel: "Awww, you missed the best part!"

I haven't played with much of RenPy's code, the most I can manage so far are the basics of transitions, character placement, dialogs, and story pathing.
For my first project I'm sure it isn't necessary or advised to be using such "flavor" tricks, but I thought it'd be something cool to sneak in after I get the main scenario and events scripted with my basic skills.
As a beginner I'd greatly appreciate any advice about doing this sort of trick and other pointers on completing my first project! :D
Last edited by CeleryNinja on Tue Jun 30, 2009 8:07 pm, edited 1 time in total.




JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Making the "countdown" a trigger

#2 Post by JQuartz »

CeleryNinja wrote:The product I'd want is something like this:
Like this:

Code: Select all

init:
    $ Ciel =Character("Ciel", color="#f00")
    
label start:
    $ during_best_part=None
    $ renpy.music.play("02.mp3", fadein=2)
label starttimer:
    if not during_best_part:
        $ ui.timer(4, ui.jumps("start_bestpart"))
        Ciel "Ah! I know this song!"
    elif during_best_part:
        $ ui.timer(4, ui.jumps("end_bestpart"))
        Ciel "Ah! I know this song!{fast}"
    
    if during_best_part== "Past best part":
        Ciel "Awww, you missed the best part!"
    elif during_best_part:
        Ciel "Isn't it wonderful?"
    elif not during_best_part:
        Ciel "The best part is coming up!"
    
    "Continue with dialogue"

label start_bestpart:
    $ during_best_part = True
    jump starttimer
    
label end_bestpart:
    $ during_best_part = "Past best part"
    jump starttimer
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Guest

Re: Making the "countdown" a trigger

#3 Post by Guest »

Thanks for the example code, but it's not quite the effect I was aiming for.
Perhaps a better way to approach it would be:

Code: Select all

init:
    $ c = Character('Ciel', color="#FFFFFF")
    $ cb = Character('Caleb', color="#c8ffc8")
label start:
    $ after_best_part=None
    $ renpy.music.play("NewWorld.ogg", fadein=2)
  #Timer starts as music plays at beginning of scene, representing the amount of time that has passed since the song began.
    $ ui.timer(24, ui.jumps("start_bestpart"))
    "During the lunch period I headed off to the music room."
label musicroom:
    if not after_best_part: 
      #However, I'm not sure if ui.timer persists through script advances or only for that particular dialog box. If not, how can I have it so that it persists?
        c "Oh! Hello there! It's the first day's lunch break and you're in here listening to classical?"
        cb "I like it...and I don't have much of an appetite during school anyways..."
        c "Classical is nice, very soothing."
        c "Ah!"
        extend " I know this song!"
      #Dialog is locked, as in the player can't advance the script
      #Or instead of locking it loops this dialog until the timer surpasses twenty-four seconds
        c "The best part's coming up!"
        c "Such a dramatic buildup..."
        c "Almost almost!"
        c "Shh! Shh!"
    #When the timer surpasses twenty-four seconds the dialog unlocks or the next click/keypress breaks off the loop
    elif after_best_part:
        c "Dvorak's New World Symphony. A masterpiece, don't you think?"

label start_bestpart:
    $ after_best_part = True
    jump musicroom
Thanks in advance for any advice or examples on how to get this kind of effect :D

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Making the "countdown" a trigger

#4 Post by JQuartz »

Guest wrote:Perhaps a better way to approach it would be:
Like this?:

Code: Select all

   
init:
    $ time_elapsed=0
    $ music_on=None
    python:
        
        def music_timer():
            if music_on:
                if time_elapsed<100:
                    ui.timer(0.10, ui.callsinnewcontext("check_timer"))
                elif time_elapsed>=100 and not after_best_part:
                    ui.timer(0.10, ui.jumps("best_part_ended"))
        config.overlay_functions.append(music_timer)
        
    $ c = Character('Ciel', color="#FFFFFF")
    $ cb = Character('Caleb', color="#c8ffc8")
label start:
    $ after_best_part=None
    $ renpy.music.play("02.mp3", fadein=2)
    
    $ music_on=True
    "During the lunch period I headed off to the music room."
label musicroom:
    if not after_best_part:
      
        c "Oh! Hello there! It's the first day's lunch break and you're in here listening to classical?"
        cb "I like it...and I don't have much of an appetite during school anyways..."
        c "Classical is nice, very soothing."
        c "Ah!"
        extend " I know this song!"
        c "The best part's coming up!"
        c "Such a dramatic buildup..."
        c "Almost almost!"
        c "Shh! Shh!"
        $ ui.interact()
    elif after_best_part:
        c "Dvorak's New World Symphony. A masterpiece, don't you think?"
        

    jump musicroom
label best_part_ended:
    $ music_on=None
    $ after_best_part=True
    jump musicroom
label check_timer:
    $ time_elapsed+=1 
    $ renpy.restart_interaction()
    return
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

CeleryNinja
Newbie
Posts: 2
Joined: Thu Nov 15, 2007 11:12 pm
Contact:

Re: Making the "countdown" a trigger

#5 Post by CeleryNinja »

That works great!
I'll be sure to remember this trick for future projects.
Thanks!




Post Reply

Who is online

Users browsing this forum: Google [Bot]