Sliding Bars & Variables [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
User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Location: USA
Contact:

Sliding Bars & Variables [SOLVED]

#1 Post by wyverngem »

I'm having trouble. I want to make a bar and an arrow above it that moves across left and right. When the player clicks, depending on what color the arrow lands on the bar it does a specific event (red, yellow, or green). Eventually, I'd like it to be a screen.

I have the animation working, just don't know how to say this is red, yellow, or green. Do you think it's possible to do a looping variable that add 1 up to 2 seconds and then subtracts 1 up to 2 seconds. Then stops when the player clicks?

Code: Select all

label start:
    image slidera animated:
        "slider-arrow.png"
        xalign .5 yalign .5
        linear 2.0 xalign 1.05
        linear 2.0 xalign 0.5
        repeat
    image slider animated:
        "slider1.png"
        pause 1.0
        "slider1b.png"
        pause 1.0
        repeat
    "Hi"
    show slidera animated
    show slider animated at truecenter
    "Coding here to make variables."
    "Player stops it."
    hide slidera animated
    "See"
    
label red:
    "You failed."

label yellow:
    "Acceptable"

label green:
    "Great!"
Attachments
slider-arrow.png
slider-arrow.png (3.39 KiB) Viewed 1487 times
slider1b.png
slider1b.png (4.01 KiB) Viewed 1487 times
slider1.png
slider1.png (4.08 KiB) Viewed 1487 times
Last edited by wyverngem on Tue Aug 14, 2012 2:39 pm, edited 1 time in total.
I ❤ Code!

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Sliding Bars & Variables

#2 Post by apricotorange »

I would say that probably the most straightforward way to do this would be to conceptually treat it like five separate animations which repeat in a sequence, one for each section of color in the bar. Then, just have a screen with some if statements which pick the current section based on some variable; you just need to display the right animation and set a timer for the correct amount of time to update the variable which contains the current section. You can express all of this directly in screen language.

If you're having trouble figuring out how to make that work, please ask; I can write out the code.

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Location: USA
Contact:

Re: Sliding Bars & Variables

#3 Post by wyverngem »

Thanks apricotorange, but I'm still at a loss. If you would please provide code, that would be very helpful.
I ❤ Code!

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Sliding Bars & Variables

#4 Post by apricotorange »

Something like the following:

Code: Select all

transform slider_animation(xstart, xend, slidetime):
    xalign xstart yalign .5
    linear slidetime xalign xend

screen slider:
    default cursection = 0
    if cursection == 0:
        add "slider-arrow.png" at slider_animation(0.5, 0.635, 0.5)
        timer 0.5 action ShowTransient("slider", cursection=1)
    elif cursection == 1:
        add "slider-arrow.png" at slider_animation(0.64, 0.775, 0.5)
        timer 0.5 action ShowTransient("slider", cursection=2)
    elif cursection == 2:
        add "slider-arrow.png" at slider_animation(0.78, 1.035, 1.0)
        timer 1.0 action ShowTransient("slider", cursection=3)
    elif cursection == 3:
        add "slider-arrow.png" at slider_animation(1.04, 1.175, 0.5)
        timer 0.5 action ShowTransient("slider", cursection=4)
    elif cursection == 4:
        add "slider-arrow.png" at slider_animation(1.18, 1.32, 0.5)
        timer 0.5 action ShowTransient("slider", cursection=0)
    if cursection == 2:
        add "slider1.png" xalign 0.5 yalign 0.5
    else:
        add "slider1b.png" xalign 0.5 yalign 0.5
    key "dismiss" action Return(cursection)

label start:
    "Hi"
    call screen slider
    "Player stops it."
    if _return == 0 or _return == 4:
        jump red
    elif _return == 1 or _return == 3:
        jump yellow
    else:
        jump green
The way I'm doing the positioning is a complete hack, but this should be enough for you to get the idea.

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Location: USA
Contact:

Re: Sliding Bars & Variables

#5 Post by wyverngem »

:) Thanks so much for the coding, it's a bit clearer. The only thing is can you example this bit of code:

Code: Select all

        add "slider-arrow.png" at slider_animation(0.5, 0.635, 0.5)
        timer 0.5 action ShowTransient("slider", cursection=1)
I don't get what the (0.5,0.635,0.5). I think it has something to do with the size, because I need to readjust it for a 1024x800 screen size. Thanks. :)
I ❤ Code!

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Sliding Bars & Variables

#6 Post by apricotorange »

Yes, the first two numbers are positions. I probably should have done it in pixels, but I was being lazy and didn't measure the images.

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Location: USA
Contact:

Re: Sliding Bars & Variables

#7 Post by wyverngem »

EDIT: Oops took out a key word. Figure out how to make it faster/slower, just need to figure out how to to oscillate back and fourth. ^^;

Code: Select all

transform slider_animation(xstart, xend, slidetime):
    xpos xstart ypos 400
    linear slidetime xpos xend

screen slider:
    default cursection = 0
    if cursection == 0:
        add "slider-arrow.png" at slider_animation(330, 393, 0.5)
        timer 0.5 action ShowTransient("slider", cursection=1)
    elif cursection == 1:
        add "slider-arrow.png" at slider_animation(392, 458, 0.5)
        timer 0.5 action ShowTransient("slider", cursection=2)
    elif cursection == 2:
        add "slider-arrow.png" at slider_animation(459, 567, 1.0)
        timer 1.0 action ShowTransient("slider", cursection=3)
    elif cursection == 3:
        add "slider-arrow.png" at slider_animation(567, 631, 0.5)
        timer 0.5 action ShowTransient("slider", cursection=4)
    elif cursection == 4:
        add "slider-arrow.png" at slider_animation(632, 693, 0.5)
        timer 0.5 action ShowTransient("slider", cursection=0)
    if cursection == 2:
        add "slider1.png" xpos 330 ypos 400
    else:
        add "slider1b.png" xpos 330 ypos 400
    key "dismiss" action Return(cursection)
I ❤ Code!

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Sliding Bars & Variables

#8 Post by apricotorange »

Oh... that's easy enough: just use ten states instead of five. :)

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Location: USA
Contact:

Re: Sliding Bars & Variables

#9 Post by wyverngem »

Got it! ^_^ Thanks for the help!
I ❤ Code!

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Sliding Bars & Variables [SOLVED]

#10 Post by PyTom »

Honestly - if we have a good programmer who's willing to try, this would be a great use-case for a creator-defined displayable.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Location: USA
Contact:

Re: Sliding Bars & Variables [SOLVED]

#11 Post by wyverngem »

Feel free, you can use the images too. They were temporary for me.
I ❤ Code!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]