Button actions

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
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Button actions

#1 Post by iDweadith »

Hi I'm a bit confused

Is the screen action the right way to make a button doing something on click?

I mean, I'm using an imagebutton so when I click on it I want a text to appear, do I have to call a screen with the text in it?

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Button actions

#2 Post by isobellesophia »

iDweadith wrote: Sun May 17, 2020 12:20 pm Hi I'm a bit confused

Is the screen action the right way to make a button doing something on click?

I mean, I'm using an imagebutton so when I click on it I want a text to appear, do I have to call a screen with the text in it?

Code: Select all

screen menu():
text "Hello world!"

Code: Select all

label start:
show screen menu
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Re: Button actions

#3 Post by iDweadith »

I mean in order to make an imagebutton works is that below the right way?

Code: Select all


imagebutton: 
	action: Jump("text")

screen text():
text "Hello world!"

Also I'm not understanding the difference between Call and Jump

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Button actions

#4 Post by isobellesophia »

Jump is for labels, call screen is used for calling screen before you continue to the novel.

https://www.renpy.org/doc/html/label.ht ... -statement
https://www.renpy.org/doc/html/label.ht ... -statement

Code: Select all

screen textx():
   imagebutton auto "button_&s.png" action Show("text") xpos 600
   
screen text:
   text "Hello world"

Code: Select all

label start:
    show screen textx
I am a friendly user, please respect and have a good day.


Image

Image


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

Re: Button actions

#5 Post by Alex »

iDweadith wrote: Sun May 17, 2020 12:20 pm Hi I'm a bit confused

Is the screen action the right way to make a button doing something on click?

I mean, I'm using an imagebutton so when I click on it I want a text to appear, do I have to call a screen with the text in it?
That depends of what you trying to achieve.
This might be

Code: Select all

screen button_scr():
    imagebutton:
        align (0.3, 0.5)
        idle "idle_img.png"
        hover "hover_img.png"
        action ToggleScreen("my_scr")

    imagebutton:
        align (0.7, 0.5)
        idle "another_idle_img.png"
        hover "another_hover_img.png"
        action Show("another_scr")

screen my_scr():
    text "Hello world!" align (0.5, 0.1)

screen another_scr():
    timer 1.0 action Hide("another_scr")
    text "Hello world!" align (0.5, 0.15)

label start:
    "..."
    show screen button_scr
    "... ..."
    "?!"
https://www.renpy.org/doc/html/screen_actions.html#Show
https://www.renpy.org/doc/html/screen_a ... ggleScreen
https://www.renpy.org/doc/html/screen_actions.html#Hide
https://www.renpy.org/doc/html/screens.html#timer

User avatar
iDweadith
Regular
Posts: 63
Joined: Sun Mar 01, 2020 4:15 pm
Contact:

Re: Button actions

#6 Post by iDweadith »

Thank you guys! So can I do something like below?

Code: Select all

screen button_1():
    imagebutton:
        action Jump("hello_world")
       
label start:
    show screen button_1
    
label hello_world:
	"Hello World"

So in my code I made a little inventory every item is an imagemap, I want that when I click on an item it gives for example +1 in thirsty

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

Re: Button actions

#7 Post by Alex »

iDweadith wrote: Mon May 18, 2020 9:07 am ... So can I do something like below?...
While you can, take in mind that showing screen won't stop Ren'Py from executing your code farther. So, the exact code you've posted will show your button screen and immediately run the 'hello_world' label (the next line of code).

Check this thread - viewtopic.php?f=51&t=39572#p422964

Post Reply

Who is online

Users browsing this forum: Google [Bot], henne, Majestic-12 [Bot]