How do I make a button do something?

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
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

How do I make a button do something?

#1 Post by namastaii » Wed Feb 04, 2015 2:34 pm

How do I tell a button to do something specific? I've made screens and I've made buttons that can return to the last page/screen etc
but

I don't know how to have the button start a label or an action of my own?

This is ..what I have. I know it's wrong. Am I close though?

Code: Select all

screen action_screen:
    frame xalign 1.0 yalign 0.0:
        has vbox
        hbox:
            if "Candy Bar" in items:
                textbutton "Eat Candy Bar" action jump label eat_candy_bar
        vbox xalign 0.9 yalign 0.370:
            textbutton "Done" action Return()
            
            
label action_screen_label:
    call screen action_screen
    return
            
label eat_candy_bar:
    $ items.remove("Candy Bar")
    show screen intelligence_screen
    $ intelligence += 1
    hide screen intelligence_screen
I'm just trying to test it out so I can actually use it for real things in my game.
For example like in my code, I want to have an inventory of something. I have an action button and inventory button.
The inventory button just shows what I have. I wasn't sure how to make it so the text that is added to the inventory could actually be interactive so I just created an action button that will open up a list of buttons to interact with.
if the character has a candy bar in their inventory, it will show up and they can consume it and it is taken from their inventory and they gain points from it etc.

How would I go about making this work?
Or to just simply make the inventory list items be interactive instead so I don't need an action button?
Just have the person open their inventory and can click on the item and use it?

I've tried looking this up but I haven't had any luck.

Thank you!

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How do I make a button do something?

#2 Post by Alex » Wed Feb 04, 2015 3:02 pm


User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I make a button do something?

#3 Post by namastaii » Wed Feb 04, 2015 3:17 pm

Yeah, I looked at that page but it's not specific enough for what I'm trying to accomplish unfortunately.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I make a button do something?

#4 Post by namastaii » Wed Feb 04, 2015 3:18 pm

I've tried action jump("blah")
and tried action show("blah")
and it tells me theres no such thing as jump or show ? so ...idk

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I make a button do something?

#5 Post by namastaii » Wed Feb 04, 2015 3:34 pm

I wish I could figure out a way to make the items list that appears in the inventory interactive.

Like..i Know $ items_list = textbutton(" ".join(items)) doesn't work. or $ items_list = textbutton " ".join(items)

There is no way to change the output of the items list? rather than just text but something clickable?

User avatar
octacon100
Regular
Posts: 163
Joined: Thu Sep 12, 2013 11:23 pm
Projects: Regeria Hope
Organization: Golden Game Barn
IRC Nick: Octacon100
Location: Boston, MA
Contact:

Re: How do I make a button do something?

#6 Post by octacon100 » Wed Feb 04, 2015 3:47 pm

So, with screen language, you have to be very careful about capital letters. Show() and Jump() will work, but show() and jump() will not.

Also, try looking at for in screen language: http://www.renpy.org/doc/html/screens.html#for

That should do something similar to what you want.
Image
Current Digital Projects -
Image
Regiera Hope Completed Game Forum Post

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I make a button do something?

#7 Post by namastaii » Wed Feb 04, 2015 3:51 pm

I'll try that. It's just that lowercase jump works when I'm jumping from page to page so I assumed it was lowercase.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I make a button do something?

#8 Post by namastaii » Wed Feb 04, 2015 3:52 pm

Yeah...It's still not working

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I make a button do something?

#9 Post by namastaii » Wed Feb 04, 2015 3:54 pm

Wait, I think I got it working.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I make a button do something?

#10 Post by namastaii » Wed Feb 04, 2015 3:55 pm

YESSS

Thank you :)

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I make a button do something?

#11 Post by namastaii » Wed Feb 04, 2015 3:57 pm

Here's the working code:

Code: Select all

screen inv_screen:
    side "c b r":
        area (590, 10, 200, 200)
        viewport id "vp":
            draggable True
            mousewheel True
            vbox:
                
                text "{color=#ff6699}Money: $[money]{/color}" 
                text "{color=#ccccff}Inventory:{/color}"
                #
                for i in range(len(items)):
                    
                    if "Candy Bar" in items:
                        
                        textbutton "Candy Bar" action Jump("eat_candy_bar")
                    if "Rose" in items:
                        textbutton "Rose"
                
                null height 10
                null height 10
        bar value XScrollValue("vp")
        vbar value YScrollValue("vp")
    vbox xalign 0.9 yalign 0.370:
        textbutton "Done" action Return()
        
label inv_screen_label:
    call screen inv_screen
    return

Code: Select all

label eat_candy_bar:
    $ items.remove("Candy Bar")
    show screen intelligence_screen
    "You've eaten a Candy Bar."
    
    $ intelligence += 1
    hide screen intelligence_screen
Last edited by namastaii on Wed Feb 04, 2015 4:04 pm, edited 1 time in total.

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: How do I make a button do something?

#12 Post by philat » Wed Feb 04, 2015 3:59 pm

No offense, dude, but reading the documentation carefully and looking at the cookbook section would solve most of your problems.

Sample inventory system: http://lemmasoft.renai.us/forums/viewto ... 51&t=23071

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I make a button do something?

#13 Post by namastaii » Wed Feb 04, 2015 4:05 pm

No offense but I actually spent a good hour looking through all sorts of forum posts and cookbook/tutorial/documentation for this. and it's mostly just because I didn't capitalize the 'jump' action.

Post Reply

Who is online

Users browsing this forum: zyric