Page 1 of 1

Sliding Bars & Variables [SOLVED]

Posted: Sat Aug 11, 2012 11:51 pm
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!"

Re: Sliding Bars & Variables

Posted: Sun Aug 12, 2012 4:12 am
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.

Re: Sliding Bars & Variables

Posted: Sun Aug 12, 2012 2:01 pm
by wyverngem
Thanks apricotorange, but I'm still at a loss. If you would please provide code, that would be very helpful.

Re: Sliding Bars & Variables

Posted: Sun Aug 12, 2012 10:23 pm
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.

Re: Sliding Bars & Variables

Posted: Mon Aug 13, 2012 2:28 am
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. :)

Re: Sliding Bars & Variables

Posted: Mon Aug 13, 2012 1:07 pm
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.

Re: Sliding Bars & Variables

Posted: Mon Aug 13, 2012 2:13 pm
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)

Re: Sliding Bars & Variables

Posted: Mon Aug 13, 2012 11:22 pm
by apricotorange
Oh... that's easy enough: just use ten states instead of five. :)

Re: Sliding Bars & Variables

Posted: Tue Aug 14, 2012 1:07 am
by wyverngem
Got it! ^_^ Thanks for the help!

Re: Sliding Bars & Variables [SOLVED]

Posted: Tue Aug 14, 2012 5:23 pm
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.

Re: Sliding Bars & Variables [SOLVED]

Posted: Tue Aug 14, 2012 11:34 pm
by wyverngem
Feel free, you can use the images too. They were temporary for me.