How to call a screen from an imagebutton screen?

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
twodee
Newbie
Posts: 12
Joined: Tue May 08, 2018 4:30 pm
Contact:

How to call a screen from an imagebutton screen?

#1 Post by twodee » Tue May 08, 2018 5:48 pm

Basically, I'm creating an always-present folder that, when clicked, shows an imagebutton, that when clicked shows another, and when that one's clicked it shows another and so on. The always-present folder will remain but will be opened (it'll show an open folder instead of a closed one) and when it's clicked it will take the player back to the game and change the open folder back to the closed folder. To my knowledge though, I can't call a screen from a screen, and the "use" tag doesn't seem to work. What should I do?

I'm also not sure how to code the open folder so that when it's clicked, it'll hide the imagebuttons that the closed-folder opened and will also make it so that the closed-folder reappears. If someone could help with that, that'd be great.

Screens:

Code: Select all

screen folder_closed:
    $ show_folder = True
    zorder 100
    imagebutton auto "gui/closedfolder_%s.png" action use fileone xpos 1686 ypos 100 focus_mask True
    
screen fileone:
    zorder 100
    imagebutton "gui/fileone_%s.png" action use filetwo xpos 960 ypos 540 focus_mask True
    
screen filetwo:
    imagebutton "gui/filetwo_%s.png" action use filethree xpos 960 ypos 540 focus_mask True
    
screen filethree:
    imagebutton "gui/filethree_%s.png" action use fileone xpos 960 ypos 540 focus_mask True

The error I'm getting is caused by me using the "use" tag. If anyone wants to see it, here it is:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 24: u'fileone' is not a keyword argument or valid child for the imagebutton statement.
    imagebutton auto "gui/closedfolder_%s.png" action use fileone xpos 1686 ypos 100 focus_mask True
                                                                    ^

File "game/screens.rpy", line 28: expected a keyword argument, colon, or end of line.
    imagebutton "gui/fileone_%s.png" action use filetwo xpos 960 ypos 540 focus_mask True
                ^

File "game/screens.rpy", line 31: expected a keyword argument, colon, or end of line.
    imagebutton "gui/filetwo_%s.png" action use filethree xpos 960 ypos 540 focus_mask True
                ^

File "game/screens.rpy", line 34: expected a keyword argument, colon, or end of line.
    imagebutton "gui/filethree_%s.png" action use fileone xpos 960 ypos 540 focus_mask True
                ^

Ren'Py Version: Ren'Py 6.99.14.3.3347
Tue May 08 17:27:14 2018

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

Re: How to call a screen from an imagebutton screen?

#2 Post by kivik » Tue May 08, 2018 5:58 pm

You can't call screens, but you can show screens using the Show() command, which may or may not be what you're looking for.

You can use an If() action for your always present folder - so that if it's opened (use a screen variable to track it), it'll close (along with all other screens that opened from it), otherwise it'll turn open and show the first screen with the image button.

For ease, you probably want to create a separate layer for these screens, so that you can clear them out in one go by clearing that particular layer.


If what you're doing is what I think you're doing (a hierarchical folder / list system), it's going to be a fiddly bit of code and design I think (are these folders dynamic in nature? do they need to open in relative position to their parent? etc.)

twodee
Newbie
Posts: 12
Joined: Tue May 08, 2018 4:30 pm
Contact:

Re: How to call a screen from an imagebutton screen?

#3 Post by twodee » Tue May 08, 2018 7:30 pm

kivik wrote:
Tue May 08, 2018 5:58 pm
You can't call screens, but you can show screens using the Show() command, which may or may not be what you're looking for.
I tried that, but still got an error message:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 24: u'show' is not a keyword argument or valid child for the imagebutton statement.
    imagebutton auto "gui/closedfolder_%s.png" action show(fileone) xpos 1686 ypos 100 focus_mask True
                                                          ^

File "game/screens.rpy", line 29: expected a keyword argument, colon, or end of line.
    imagebutton "gui/fileone_%s.png" action show(filetwo) xpos 960 ypos 540 focus_mask True
                ^

File "game/screens.rpy", line 33: expected a keyword argument, colon, or end of line.
    imagebutton "gui/filetwo_%s.png" action show(filethree) xpos 960 ypos 540 focus_mask True
                ^

File "game/screens.rpy", line 37: expected a keyword argument, colon, or end of line.
    imagebutton "gui/filethree_%s.png" action show(fileone) xpos 960 ypos 540 focus_mask True
                ^

Ren'Py Version: Ren'Py 6.99.14.3.3347
Tue May 08 19:25:53 2018
If what you're doing is what I think you're doing (a hierarchical folder / list system), it's going to be a fiddly bit of code and design I think (are these folders dynamic in nature? do they need to open in relative position to their parent? etc.)
What I'm doing isn't hierarchical, or at least, it doesn't have to be. It's a simulation of browsing through a file folder, flipping thru the papers. I can make it hierarchical if it'd make the code easier, but it isn't necessarily what I'm going for.

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

Re: How to call a screen from an imagebutton screen?

#4 Post by Imperf3kt » Tue May 08, 2018 7:41 pm

Traceback suggests you used 'show'.
The 'show' needs to be capitalised.
Show()
Not
show()
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

twodee
Newbie
Posts: 12
Joined: Tue May 08, 2018 4:30 pm
Contact:

Re: How to call a screen from an imagebutton screen?

#5 Post by twodee » Tue May 08, 2018 7:51 pm

Imperf3kt wrote:
Tue May 08, 2018 7:41 pm
The 'show' needs to be capitalised.
Thanks, this fixed most of it! However, I'm still getting an error. It says that "fileone" isn't defined?

Code: Select all

  File "game/screens.rpy", line 24, in execute
    imagebutton auto "gui/closedfolder_%s.png" action Show(fileone) xpos 1686 ypos 100 focus_mask True
  File "game/screens.rpy", line 24, in keywords
    imagebutton auto "gui/closedfolder_%s.png" action Show(fileone) xpos 1686 ypos 100 focus_mask True
NameError: name 'fileone' is not defined

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

Re: How to call a screen from an imagebutton screen?

#6 Post by Imperf3kt » Tue May 08, 2018 7:59 pm

Missed that. Wrap it in quotes.

Code: Select all

action Show("fileone")
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

twodee
Newbie
Posts: 12
Joined: Tue May 08, 2018 4:30 pm
Contact:

Re: How to call a screen from an imagebutton screen?

#7 Post by twodee » Wed May 09, 2018 5:36 pm

That worked, thanks!

Back to the folder appearing open/closed, I still can't figure that out. My game runs smoothly, however, when the folder is opened, the closed-folder icon doesn't turn into the open-folder icon, making it impossible to close the folder.

Code: Select all

init -1 python:
    def hide_screens():
        renpy.hide_screen("fileone")
        renpy.hide_screen("filetwo")
        renpy.hide_screen("filethree")
        
init -1 python:
    def hide_folder():
        renpy.hide_screen("folder_closed")screen folder_closed:
    $ show_folder = True
    zorder 100
    imagebutton auto "gui/closedfolder_%s.png" action Show("fileone") xpos 1686 ypos 75 focus_mask True
    
screen fileonefile:
    $ show_folder = False
    zorder 100
    imagebutton idle "gui/fileone_IDLE.png" hover "gui/fileone_HOVER.png" action [hide_folder, Show("filetwo")] xalign 0.5 yalign 1 focus_mask True
    
screen filetwo:
    $ show_folder = False
    $ show_folder_open = True
    imagebutton idle "gui/filetwo_IDLE.png" hover "gui/filetwo_HOVER.png" action [hide_folder, Show("filethree")] xalign 0.5 yalign 1 focus_mask True
    
screen filethree:
    $ show_folder = False
    $ show_folder_open = True
    imagebutton idle "gui/filethree_IDLE.png" hover "gui/filethree_HOVER.png" action [hide_folder, Show("fileone")] xalign 0.5 yalign 1 focus_mask True
    
screen folder_open:
    $ show_folder = False
    $ show_folder_open = True
    imagebutton idle "gui/openfolder_IDLE.png" hover "gui/openfolder_HOVER.png" action [hide_screens, Show("folder_closed")] xpos 1686 ypos 75 focus_mask True
What I'm trying to achieve is that, when folder_closed is clicked, it opens the files. As long as any of the files are open, the screen folder_open is visible and clickable while the screen folder_closed is not. When folder_open is clicked, the files should all close and the screen folder_closed should be visible again. I also have the follow a couple lines down:

Code: Select all

    if show_quick_menu1:
        use quick_menu1
    if show_folder_closed:
        use folder_closed
    if show_folder_open:
        use folder_open
In the beginning of my actual script, I have this:

Code: Select all

    $ show_folder_closed = True
    $ show_folder_open = False
If you have any ideas, I'd love to hear them. Thanks for the help so far :D

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

Re: How to call a screen from an imagebutton screen?

#8 Post by Imperf3kt » Wed May 09, 2018 5:55 pm

I lack time to give a full example so I'll mention a useful function.
You can combine renpy.get_screen("screenname") with a conditional for your imagebutton.

For example (psuedocode)

Code: Select all

    if renpy.get_screen("folder_open"):
        #imagebutton that closes the folder
    if renpy.get_screen("folder_closed"):
        #imagebutton that opens folder
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

twodee
Newbie
Posts: 12
Joined: Tue May 08, 2018 4:30 pm
Contact:

Re: How to call a screen from an imagebutton screen?

#9 Post by twodee » Thu May 10, 2018 4:49 pm

Seriously, thank you so much for the help so far. I still get an error though:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 28: expected statement.
    imagebutton:
               ^

File "game/screens.rpy", line 36: expected statement.
    imagebutton:
               ^

Ren'Py Version: Ren'Py 6.99.14.3.3347
Thu May 10 16:46:11 2018
Here's my code:

Code: Select all

if renpy.get_screen("folder_open"):
    imagebutton:
        idle "gui/openfolder_IDLE.png"
        hover "gui/openfolder_HOVER.png"
        action [hide_screens, Show("folder_closed")]
        xpos 1686
        ypos 75
        focus_mask True
elif renpy.get_screen("folder_closed"):
    imagebutton:
        auto "gui/closedfolder_%s.png"
        action Show("fileone")
        xpos 1686
        ypos 75
        focus_mask True

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

Re: How to call a screen from an imagebutton screen?

#10 Post by Imperf3kt » Thu May 10, 2018 5:07 pm

Try putting the imagebutton on a single line. I think imagebuttons don't play well as a block.
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

twodee
Newbie
Posts: 12
Joined: Tue May 08, 2018 4:30 pm
Contact:

Re: How to call a screen from an imagebutton screen?

#11 Post by twodee » Thu May 10, 2018 6:12 pm

Unfortunately, that got me the same error.

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

Re: How to call a screen from an imagebutton screen?

#12 Post by Imperf3kt » Thu May 10, 2018 7:00 pm

I see you've used elif
I'm not sure, but I think thats a bad idea. Just use two if statements.
The reason for this is what if you're on neither screen?
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

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to call a screen from an imagebutton screen?

#13 Post by Remix » Thu May 10, 2018 7:43 pm

Two points:

1) Never use a function as a button action, instead use the Ren'py action named Function...
action [ Function( hide_screens ) ]

2) You can use the Ren'py action If() to cause conditional actions...
action [ If( test_condition, list_of_actions_for_True_result, list_of_actions_for_False_result ) ]

You should probably read through Ren'py's supported actions in the documentation btw
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: No registered users