Buttons and Doors

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.
Message
Author
User avatar
Paul Kinsella
Regular
Posts: 29
Joined: Sat May 02, 2020 9:53 am
Contact:

Buttons and Doors

#1 Post by Paul Kinsella »

I have done a search and could not find a previous post on this topic. Perhaps I am the first. Or I searched under the wrong search terms.
I'd like to have clickable doors in my games. For example: there will be a room with a door labeled "Exit". When clicked on, the player is taken out to the parking lot. Another door reads "Shooting Range". If a player clicks on that - he is taken to the shooting range. You get the idea.
Along those lines I would like to have clickable "buttons" in the game for all sorts of things... If the player clicks on a bush - a bloody knife is shown. If the player clicks on the buttons on an elevator - they take the player to the correct floor. You get the idea.
Keep in mind that I'm a novice who has only just finished the "quickstart" manual.

User avatar
Paul Kinsella
Regular
Posts: 29
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Buttons and Doors

#2 Post by Paul Kinsella »

Oops... Perhaps I should have googled first. :D I've found some information at https://www.renpy.org/dev-doc/html/screens.html that might answer my questions. Meanwhile if anyone wants to give me additional sources or tutorials you have found useful - please let me know.

User avatar
Paul Kinsella
Regular
Posts: 29
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Buttons and Doors

#3 Post by Paul Kinsella »

I think the term I was wanting (but did not know) to search for was "imagebotton"...
viewtopic.php?t=22565
:)

User avatar
Paul Kinsella
Regular
Posts: 29
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Buttons and Doors

#4 Post by Paul Kinsella »

I was unable to run the "imagebotton" example that was located on this page here: viewtopic.php?t=22565
Can anyone understand why I got this error? Thank you, in advance, for your help... :D



```
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/example.rpy", line 113, in script
image example = __Example()
Exception: Not a displayable: <store._m1_example__Example object at 0x045B4D10>

-- Full Traceback ------------------------------------------------------------

Full traceback:
File "game/example.rpy", line 113, in script
image example = __Example()
File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\ast.py", line 1017, in execute
renpy.exports.image(self.imgname, img)
File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\exports.py", line 375, in image
d = renpy.easy.displayable(d)
File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\easy.py", line 136, in displayable
raise Exception("Not a displayable: %r" % (d,))
Exception: Not a displayable: <store._m1_example__Example object at 0x045B4D10>

Windows-8-6.2.9200
Ren'Py 7.3.5.606
Renpy Imagebuttons GUI Sample 1.0
Tue May 12 04:46:13 2020
```

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Buttons and Doors

#5 Post by Milkymalk »

That example is 7 years old. There are probably some parts that don't work with modern versions of Renpy, and there is definitely some stuff in there that is (today) considered bad style.
https://www.renpy.org/dev-doc/html/scre ... magebutton has a pretty decent documentation for imagebuttons. If it confuses you, forget the "auto" keyword for now and work with the "idle" and "hover" keywords only, until you know how everything works.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Chaste Degenerate
Newbie
Posts: 5
Joined: Tue May 12, 2020 5:03 am
Contact:

Re: Buttons and Doors

#6 Post by Chaste Degenerate »

Thundorn has videos on a similar subject with clickable icons on a map. Doors should work the same I would believe.
This is part 1 of 4 parts of this little section, and video 21 of a Ren'Py course he put on YouTube:

https://www.youtube.com/watch?v=1CikDL3 ... h&index=21

I'm going through his YouTube course right now. This content does stack on previous content, so if you need the previous content this link is specifically linked to the playlist.

It helps that this is about a year old, so fairly current. I believe he's a member here. I know he has a link to this forum under his videos.
I'm an idiot, don't take advice from me.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Buttons and Doors

#7 Post by trooper6 »

Paul Kinsella wrote: Tue May 12, 2020 5:56 am I was unable to run the "imagebotton" example that was located on this page here: viewtopic.php?t=22565
Can anyone understand why I got this error? Thank you, in advance, for your help... :D



```
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/example.rpy", line 113, in script
image example = __Example()
Exception: Not a displayable: <store._m1_example__Example object at 0x045B4D10>

-- Full Traceback ------------------------------------------------------------

Full traceback:
File "game/example.rpy", line 113, in script
image example = __Example()
File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\ast.py", line 1017, in execute
renpy.exports.image(self.imgname, img)
File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\exports.py", line 375, in image
d = renpy.easy.displayable(d)
File "C:\Users\paul\renpy\renpy-7.3.5-sdk\renpy\easy.py", line 136, in displayable
raise Exception("Not a displayable: %r" % (d,))
Exception: Not a displayable: <store._m1_example__Example object at 0x045B4D10>

Windows-8-6.2.9200
Ren'Py 7.3.5.606
Renpy Imagebuttons GUI Sample 1.0
Tue May 12 04:46:13 2020
```
The error in that files is fixed later in the thread:
viewtopic.php?p=455107#p455107
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Paul Kinsella
Regular
Posts: 29
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Buttons and Doors

#8 Post by Paul Kinsella »

Thank you all so much! :D I'm sure that after a few more months Ren'py will not seen quite so daunting.

User avatar
Paul Kinsella
Regular
Posts: 29
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Buttons and Doors

#9 Post by Paul Kinsella »

I'm afraid I'm still struggling with buttons (imagebuttons). If only I could see a complete and functional example of button code, I'm sure I'd make better progress. Here's something I put together, but does not function. I'm having a devil of a time searching for "imagebutton code examples". Can any one provide me with a sample code that fits this format?...

image office = "office1.jpg"
label start:
scene office
"Welcome!"
imagebutton:
idle "idolbutton.jpg"
hover "hoverbutton.jpg"
xpos 100 ypos 100
action Jump('test')
label test:
"Test text"
return
Last edited by Paul Kinsella on Sat May 16, 2020 8:46 am, edited 1 time in total.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Buttons and Doors

#10 Post by hell_oh_world »

Please always refer to the official renpy documentation, what you're trying to find, you can always easily find that by searching / googling like `renpy imagebutton`, the first one that pop ups should be from the official renpy documentation...
https://www.renpy.org/dev-doc/html/scre ... magebutton

setting things aside, since imagebuttons are displayables they are used in screens and not inside labels...

Code: Select all

screen something:
    imagebutton:
        idle "idolbutton.jpg"
        hover "hoverbutton.jpg"
        xpos 100 ypos 100
        action Jump('test')

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: Buttons and Doors

#11 Post by isobellesophia »

I dont think youtube videos can help out at all, some of these videos were outdated, its better to ask here or learn in the main site of the renpy instead, youtube tutorials are harder than i expected, some of the youtuber itself wont reply to the commenters unlike here.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
Paul Kinsella
Regular
Posts: 29
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Buttons and Doors

#12 Post by Paul Kinsella »

Thank you for your help. Renpy.org was the first place I looked before posting my question. Unfortunately I could not find a complete and functional example of button code there. I found parts of code there (and other places too). But I was looking for something I could copy'n'paste into a new ren'py program and see how it works. I appreciate the time you took to locate the above code part. When I inserted it into the example I gave, the example would still not function. If I could trouble you to help me alter my code (shown below) so it becomes a complete and functional example, I'd be VERY grateful. Thank you again for your help. :D

image office = "office1.jpg"
label start:
scene office
"Welcome!"
screen something:
imagebutton:
idle "idolbutton.jpg"
hover "hoverbutton.jpg"
xpos 100 ypos 100
action Jump('test')
label test:
"Test text"
return

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Buttons and Doors

#13 Post by Milkymalk »

Code: Select all

image office = "office1.jpg"

label start:
    scene office
    "Welcome!"
    
screen something:
    imagebutton:
        idle "idolbutton.jpg"
        hover "hoverbutton.jpg"
        xpos 100 ypos 100
        action Jump('test')

label test:
    "Test text"
    return
This SHOULD already work, however it doesn't do much. You need to actually show the screen with "show screen something", preferably before the "Welcome!". Showing a screen does NOT interrupt the flow of the script. For that, you need to CALL the screen, which has a few implications for the game flow of its own.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Paul Kinsella
Regular
Posts: 29
Joined: Sat May 02, 2020 9:53 am
Contact:

Re: Buttons and Doors

#14 Post by Paul Kinsella »

Milkymalk wrote: Sat May 16, 2020 9:47 am This SHOULD already work, however it doesn't do much. You need to actually show the screen with "show screen something", preferably before the "Welcome!". Showing a screen does NOT interrupt the flow of the script. For that, you need to CALL the screen, which has a few implications for the game flow of its own.
Thank you very much! I added "show screen something" and now I have a functional example. :D Here it is if anyone else needs it...

Code: Select all

image office = "office1.jpg"
label start:
    scene office
    show screen something
    "Welcome!"
screen something:
    imagebutton:
        idle "idolbutton.jpg"
        hover "hoverbutton.jpg"
        xpos 100 ypos 100
        action Jump('test')
label test:
    "Test text"
    return

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Buttons and Doors

#15 Post by gas »

For your knowldge: you don't need to define a screen where it should be used. In fact during execution, screen definitions are skipped.

You can write down the screens wherever you want. Just before the game is launched, renpy go scanning thru all your scripts, find the screens definitions and memorize them.
So, you can call such memorized screens with the show screen (or call screen) statement wherever they are scripted.

show screen X display a screen that stay put until you don't hide it again with an hide screen X declaration. In the meanwhile renpy continue to go onward. That'ìs good for example if you want to show a clock, a calendar or some info in the interface while the story goes on.
call screen X display a screen and stop until a button do a Return() action. This way you can have the game stop and wait for you to pick something. The Return() action return a value that's automatically stored in the variable '_return', so you can check it just after to do something. The called screen hide itself automatically.

An example:

Code: Select all

label start:
    "Let's go investigate..."
    call screen doors
    if _return ==  "red":
        jump red_door
    if _return == "blue":
        jump blue_door
label red_door:
    "You picked the red door..."
    return
label blue_door:
    "You picked the blue door..."
    return
    
    
screen doors():
    vbox:
        imagebutton auto "red_door_%s" action Return("red")
        imagebutton auto "blue_door_%s" action Return("blue")

You should indepth in the docs: screen language, screen language actions and functions.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Post Reply

Who is online

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