[SOLVED] Cycling Menu Issues

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
Westeford
Regular
Posts: 151
Joined: Mon Jun 19, 2017 4:43 pm
Completed: 12 Hours to Die
Projects: Project Premonition
itch: westeford
Location: United States
Contact:

[SOLVED] Cycling Menu Issues

#1 Post by Westeford »

What I'm trying to do is make a cyling menu like in the trials in Danganronpa.

Code: Select all

#This part is defined before the debate.
    define bullet_max = 5
    define bullet_min = 1
    define bullet1 = "Autopsy"
    define bullet2 = "Beta"
    define bullet3 = "Clive"
    define bullet4 = "Dumptruck"
    define bullet5 = "Exception"

#This screen is shown during the debate.
screen gun: #Screen appears
    default bullet_selected = 1 #Always start with the first bullet selected
    imagemap:
        ground "TruthBullet/debate_ground.png" 
        hover "TruthBullet/debate_hover.png"
        idle "TruthBullet/debate_idle.png"
        #press the hotspots to cycle through the truth bullets
        hotspot (8, 553, 112, 83) action Call("bullet_up") #Up
        hotspot (8, 637, 112, 83) action Call("bullet_down")  #Down

#These labels are called through the hotspots
label bullet_up:
    if bullet_selected == bullet_max:
        $ bullet_selected = bullet_min
    else:
        $ bullet_selected += 1
    if bullet_selected == 1:
        show text "{size=50}[bullet1]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    elif bullet_selected == 2:
        show text "{size=50}[bullet2]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    elif bullet_selected == 3:
        show text "{size=50}[bullet3]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    elif bullet_selected == 4:
        show text "{size=50}[bullet4]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    elif bullet_selected == 5:
        show text "{size=50}[bullet5]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    else:
        pass
    return()
   
label bullet_down:
    if bullet_selected == bullet_min:
        $ bullet_selected = bullet_max
    else:
        $ bullet_selected -= 1
    if bullet_selected == 1:
        show text "{size=50}[bullet1]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    elif bullet_selected == 2:
        show text "{size=50}[bullet2]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    elif bullet_selected == 3:
        show text "{size=50}[bullet3]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    elif bullet_selected == 4:
        show text "{size=50}[bullet4]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    elif bullet_selected == 5:
        show text "{size=50}[bullet5]" as t0 onlayer screens:
            xalign 0.1 yalign 1.0
    else:
    return()
Everything is working except for one

4. The the hover images don't show on the buttons.

For reference here's a video of what I mean. Focus on the bottom left of the screen. Notice how it shows one truth bullet at a time and how it cycles through. Starts at 6:31
https://youtu.be/uLIHl8L7diQ?t=387

I hope what I wrote made sense.
I appreciate any input offered. Thank you very much for reading this post.
Last edited by Westeford on Thu Dec 06, 2018 4:27 pm, edited 2 times in total.

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: Cycling Menu Issues

#2 Post by DannX »

1. The first bullet doesn't show up one of the hotspots are pressed.
I don't understand what this means, but I guess it's when you press the buttons, it skips the first and last bullets depending on wich direction you go. That's because you need to check for the max and min values plus 1 (I included the solution in the example below)
2. The text doesn't hide when i hide the "gun" screen.
May be a side effect of showing the text in labels with show text statement, you would have to manually hide it each time.
I'm pretty sure I need to have the text appear in the gun screen, but I'm having a hard time actually showing the text from [bullet1], etc.
Try using text screen statement, and .format function, I use eval in my example but there could be a better way.
3. Pressing the buttons hides other text.
Not sure why this happens, again, might be because of calling labels.
4. The hover images don't show on the buttons.
Not sure either as I never use imagemaps, if you don't find a solution you could try with imagebutton.

Here's my attempt at replicating the system, using only the gun screen and a small function:

Code: Select all

# The other bullet1 to 5 variables are kept the same

default bullet_selected = 1 #Always start with the first bullet selected

screen gun(): #Screen appears
   
   #Used textbuttons since I don't have any image to test with right now
   textbutton "Bullet Up" xpos 8 ypos 553 action Function(cycle_bullet, 1)
   textbutton "Bullet Down" xpos 8 ypos 637 action Function(cycle_bullet, -1)

   #Current bullet text, displays the bullet number (for debug purposes) using eval to parse bullet + bullet_selected value
   text "{}. {}".format( bullet_selected, eval('bullet'+ str(bullet_selected)) ) xpos 136 ypos 603

init python:

    # This function changes bullet_selected's value adding whatever you pass it.
    # If you pass +1 it goes "up" and if -1 it goes "down".
    # If it gets bigger or lower than max or min, it resets the variable
    def cycle_bullet(value):

        global bullet_selected

        bullet_selected += value

        if bullet_selected == bullet_max + 1:
            bullet_selected = bullet_min
        elif bullet_selected == bullet_min -1:
            bullet_selected = bullet_max

User avatar
Westeford
Regular
Posts: 151
Joined: Mon Jun 19, 2017 4:43 pm
Completed: 12 Hours to Die
Projects: Project Premonition
itch: westeford
Location: United States
Contact:

Re: Cycling Menu Issues

#3 Post by Westeford »

DannX wrote: Thu Dec 06, 2018 1:18 pm Here's my attempt at replicating the system, using only the gun screen and a small function:

Code: Select all

# The other bullet1 to 5 variables are kept the same

default bullet_selected = 1 #Always start with the first bullet selected

screen gun(): #Screen appears
   
   #Used textbuttons since I don't have any image to test with right now
   textbutton "Bullet Up" xpos 8 ypos 553 action Function(cycle_bullet, 1)
   textbutton "Bullet Down" xpos 8 ypos 637 action Function(cycle_bullet, -1)

   #Current bullet text, displays the bullet number (for debug purposes) using eval to parse bullet + bullet_selected value
   text "{}. {}".format( bullet_selected, eval('bullet'+ str(bullet_selected)) ) xpos 136 ypos 603

init python:

    # This function changes bullet_selected's value adding whatever you pass it.
    # If you pass +1 it goes "up" and if -1 it goes "down".
    # If it gets bigger or lower than max or min, it resets the variable
    def cycle_bullet(value):

        global bullet_selected

        bullet_selected += value

        if bullet_selected == bullet_max + 1:
            bullet_selected = bullet_min
        elif bullet_selected == bullet_min -1:
            bullet_selected = bullet_max
You are amazing. This works perfectly. I just have to fix the image issues, but other than that everything is working perfectly.
Seriously, thank you so much!

Post Reply

Who is online

Users browsing this forum: No registered users