How to make a button that opens a vbox to it's right

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
zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

How to make a button that opens a vbox to it's right

#1 Post by zeroTheHero » Mon May 07, 2018 11:11 am

I've been searching for a couple days but can't seem to find a solution. To give an example, I want to make a textbutton saying 'Pokemon' that opens some buttons in a vbox to it's right (say a list of 6 pokemon names). Each button with Pokemon name then opens a vbox with Pokemon moves. Selecting a Pokemon move does some action, like damaging an enemy.

I've played around with the button's "action" property but there's no action(show) command and I can't get action(call) to work here. How should I go about this? Any help would be appreciated!

User avatar
kostek00
Regular
Posts: 129
Joined: Wed Mar 28, 2018 5:54 pm
Contact:

Re: How to make a button that opens a vbox to it's right

#2 Post by kostek00 » Mon May 07, 2018 11:42 am

Actually there is action(show) command. Here is how I'm using it:

Code: Select all

hotspot(25,484,149,40) action [Show("extra2",transition=None),Hide("extra")]
In my case this repleces whole screen menu "extra" with "extra2" and vice versa in menu "extra2". I don't if this helps you but you might find solution to show only portion of screen.

I for example would really like to know how to replace only part of screen.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to make a button that opens a vbox to it's right

#3 Post by kivik » Mon May 07, 2018 11:47 am

I haven't tried this but I'd imagine you can achieve this by using a combination of showif and ToggleScreenVariable()

Something along the lines of this (not tested):

Code: Select all

screen pokemons:
    default showbuttons = False
    hbox:
        textbutton "show buttons" action ToggleScreenVariable("showbuttons")
        showif showbuttons:
            vbox:
                textbutton "Pikachew" action Return("Pikachew")
                textbutton "Bubblesaura" action Return("Bubblesaura")
                textbutton "Charmingdan" action Return("Charmingdan")

zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: How to make a button that opens a vbox to it's right

#4 Post by zeroTheHero » Mon May 07, 2018 11:42 pm

Thanks for the replies, I really appreciate it. And sorry for getting back so late, I really needed some sleep
Anyways, I tried your codes:

@ kostek00
I saw the doc for https://www.renpy.org/doc/html/screen_a ... 0show#Show, and tried this

Code: Select all

 
screen button():
	button:
        	textbutton "Pika" action[ Show("Move1", transition = None)] 
Doesn't work :(
kivik wrote:
Mon May 07, 2018 11:47 am
I haven't tried this but I'd imagine you can achieve this by using a combination of showif and ToggleScreenVariable()

Something along the lines of this (not tested):

Code: Select all

screen pokemons:
    default showbuttons = False
    hbox:
        textbutton "show buttons" action ToggleScreenVariable("showbuttons")
        showif showbuttons:
            vbox:
                textbutton "Pikachew" action Return("Pikachew")
                textbutton "Bubblesaura" action Return("Bubblesaura")
                textbutton "Charmingdan" action Return("Charmingdan")
Wow, your code works! And it's so cool how you guys can say complex code correctly without any testing.
Firstly, when we return("Pikachew") we return a string, right? How do we return a screen with Pikachew's moves? Sorry for asking, but I couldn't find return() in the documentation apart from an example. I tried this:

(Ignore, Noob code incoming, keeping it because it makes other posts relevant)

Code: Select all

screen battle():
    screen pokemons:
        default showbuttons = False
        hbox:
            textbutton "show buttons" action ToggleScreenVariable("showbuttons")
            showif showbuttons:
                vbox:
                    textbutton "Pikachew" action Return(screen(Pikachew))
                    ...
screen Pikachew():
   vbox:
      	textbutton "Thunder" action Return("Thunder")
Doesn't work
Second, I don't really get what TogglescreenVariable does, do you know if there's a tutorial on lemma for it? I searched, but couldn't find one. Seeing some more sample code would help me understand it better I think

Thanks for your time, I really appreciate it!
Last edited by zeroTheHero on Tue May 08, 2018 12:49 am, edited 6 times in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: How to make a button that opens a vbox to it's right

#5 Post by Imperf3kt » Tue May 08, 2018 12:02 am

ToggleScreenVariable (to the best of my limited knowledge) takes a variable you define and switches it between True and False.

I don't understand the significance of "screen" in it, but basically its an on / off trigger.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: How to make a button that opens a vbox to it's right

#6 Post by zeroTheHero » Tue May 08, 2018 12:33 am

Imperf3kt wrote:
Tue May 08, 2018 12:02 am
ToggleScreenVariable (to the best of my limited knowledge) takes a variable you define and switches it between True and False.

I don't understand the significance of "screen" in it, but basically its an on / off trigger.
Thank you so much, this really helped clear kivik's code a lot for me.

To summarize my post, kivik showed me how to open a vbox from a textbutton using showif and ToggleScreenVariable

What I'm trying to do is open another vbox from textbutton in above mentioned vbox. So, I tried turning

Code: Select all

 return("Pikachew") 
in kivik's code into

Code: Select all

 return(screen(Pikachew)) 
, and defined screen Pikachew below as a vbox.

Sorry if I'm not clear, if there's any doubt I'd happily clear it for you.
Thanks

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to make a button that opens a vbox to it's right

#7 Post by kivik » Tue May 08, 2018 5:34 am

Hey sorry I had an early night and just seen this. Glad the code works, that's a pleasant surprise!

Now if you want another set of vboxes, you'd just nest another layer of vboxes, so another set of variables can be toggled to turn the second set of vboxes on and off. The way my code works isn't that it does a show screen (that shows a new screen, not a vbox) but it relies on the showif keyword.

Not sure if you click on the link I gave above (I linked it on the showif and the ToggleScreenVariable keywords) to read more about it. The idea is that you put a condition in your showif - if it's True it shows what's inside its block; otherwise it hides it, thus toggling a screen variable will show and hide the vbox for you.

To do this at a second level, you'll probably just need to use a second screen variable:

Code: Select all

screen pokemons:
    default show_pokemons = False
    default show_pokemon = False
    hbox:
        frame:
            xsize 300
            ysize 400
            textbutton "show buttons" action ToggleScreenVariable("show_pokemons")
        frame:
            xsize 300
            ysize 400
            showif show_pokemons:
                vbox:
                    textbutton "Pikachew" action SetScreenVariable("show_pokemon", "pikachew")
                    textbutton "Bubblesaura" action SetScreenVariable("show_pokemon", "bubblesaura")
                    textbutton "Charmingdan" action SetScreenVariable("show_pokemon", "charmingdan")
        frame:
            xsize 300
            ysize 400
            showif show_pokemon == "pikachew":
                vbox:
                    label "Pikachew"
                    text "Teeth"
                    text "add more stuff here"
                    textbutton "Attack" action Return("pikachew")
            showif show_pokemon == "bubblesaura":
                vbox:
                    label "Bubblesaura"
                    text "Soap"
                    text "add more stuff here"
                    textbutton "Attack" action Return("bubblesaura")
            showif show_pokemon == "charmingdan":
                vbox:
                    label "Charmingdan"
                    text "Charisma"
                    text "add more stuff here"
                    textbutton "Attack" action Return("charmingdan")
This time the screen variable takes a string, because we want to know which pokemon you've clicked on, and we can set it using SetScreenVariable().
I've also added frames this time to add a bit of a placeholder for where these vboxes will be.

Now the Return function, I assumed you'll be calling the screen from your code, and thus Return() is the best way to return what choice your player made. So your game code should look something like this:

Code: Select all

call screen pokemons
if _return:
    call expression _return + "_attack"
Or maybe you have it in a condition block:

Code: Select all

call screen pokemons
if _return == "pikachew"
    # do bite attack
if _return == "bubblesaura"
    # do bubble attack stuff

etc..
Even the screen code can be simplified if you use a list, dictionary or ordereddict to store the list of pokemons and their corresponding information. However you may want to get to grips with this first.

zeroTheHero
Regular
Posts: 64
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: How to make a button that opens a vbox to it's right

#8 Post by zeroTheHero » Tue May 08, 2018 12:31 pm

kivik thank you so much for taking your time out for this! I went through your code and it made so much sense. It's funny how I knew I just had to repeat your code, but for the life of me I couldn't figure out how. Even if I'd known about SetScreenVariable, I doubt I'd be able to write what you've come up with. I can't imagine the mental gymnastics programmers go through to solve 'simple' problems like this. Seriously, thanks, you've not only solved my problem but also made me a better coder(I hope XD)

On a side note, have you played any pokemon? The names you chose suggest you do, but the attacks... XD

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to make a button that opens a vbox to it's right

#9 Post by kivik » Tue May 08, 2018 12:39 pm

zeroTheHero wrote:
Tue May 08, 2018 12:31 pm
kivik thank you so much for taking your time out for this! I went through your code and it made so much sense. It's funny how I knew I just had to repeat your code, but for the life of me I couldn't figure out how. Even if I'd known about SetScreenVariable, I doubt I'd be able to write what you've come up with. I can't imagine the mental gymnastics programmers go through to solve 'simple' problems like this. Seriously, thanks, you've not only solved my problem but also made me a better coder(I hope XD)

On a side note, have you played any pokemon? The names you chose suggest you do, but the attacks... XD
Glad to be of help! To be fair you had the idea, and you were curious enough to wonder if it's possible, and I just had a play with it based on what I knew. I only knew all that stuff because I've been lurking and reading every thread on the forum as well, I didn't know about showif until a few weeks ago!

I did play the first gen pokemon games (I'm pretty ancient), I just thought pikachew was funny and had fun with the rest :P

User avatar
Qlara
Regular
Posts: 80
Joined: Fri Nov 28, 2014 10:22 am
Completed: Carmilla
Skype: kantonija
itch: visualgothic
Location: Berlin
Contact:

Re: How to make a button that opens a vbox to it's right

#10 Post by Qlara » Wed May 09, 2018 12:58 am

edit, post deleted:
Sorry posted in the wrong thread.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], _ticlock_