Jumping/returning to labels from screens

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
Rainvillain
Regular
Posts: 76
Joined: Thu Mar 05, 2015 11:27 am
Contact:

Jumping/returning to labels from screens

#1 Post by Rainvillain »

Hi there!

I've create a very simple inventory/journal screen where you can look at the game's world map along with any in-game documentations you might have come across. The player has access to this journal at any point during the game.

Right now there's an imagebutton that hovers just next to the dialogue window at all times. When you click on it, it brings you to the journal. That part seems to work fine. This is the code in script.rpy

Code: Select all

define e = Character('Eileen', color="#c8ffc8")


# The game starts here.
label start:
    scene bgsky
    show screen journal_icon
    e "Hey, do you notice the icon on the right?"
    e "I want you to click on it. And then when you're done, return to here!"
    e "Try clicking on it."
    e "..."
    e "Did you click on it..?"
screen journal_icon:
    imagebutton auto "house_%s.png" action ShowMenu("journal_open") xpos 1100 ypos 510 focus_mask True

label error:
    e "Man, you should not be seeing this..."

label fullmap:
    scene map
    $ renpy.pause ()
    return

label documents:
    scene documentation
    e "Eventually there will be a bunch of imagebuttons of the documents here..."
    return
And then the ShowMenu("journal_open") leads to a piece of code I've written in the screens.rpy file.

Code: Select all

##############################################################################
# Journal
#
screen journal_open():

    imagemap:
        ground "journal"
        hover "journal_hover"

        hotspot (189, 125, 375, 230) action Jump("fullmap")
        hotspot (123,583,70,74) action Return()
        hotspot (1107,505,172,66) action ShowMenu("preferences")
        hotspot (1107,325,172,63) action ShowMenu("save")
        hotspot (1108,422,171,65) action ShowMenu("load")
        hotspot (1109, 238, 170, 63) action Jump("documents")
        #hotspot (0,0,0,0) action MainMenu()
        #hotspot (0,0,0,0) action Help()
        hotspot (1108,584,171,67) action Quit()

So here's where I have a few problems.


1. First of all the two actions that lead to labels in the script.rpy, Jump("fullmap") and Jump("documents"), don't seem to be displaying any images.
In the case of label fullmap, this means nothing happens. In the case of label documentations then it means Eileen says her line but it doesn't show the scene.

I imagine this has something to do with this menu screen being in front of the scene..? Or is there some rule about not being able to show images while being in a screen like the one I've made?

2. My second problem is that once I've clicked on load, save or preferences, and have been brought to their respective new screens, I can't seem to go back to my journal screen. The return buttons on each of those screens seem to return me directly to the game, skipping over the journal. I would prefer it return me to the journal, and then from the journal I would then return to the game.

I figure I'm doing something wrong with my jumping/returning of screens and labels but I can't figure out what it is!
Any help would be greatly appreciated.

Counter Arts
Miko-Class Veteran
Posts: 649
Joined: Fri Dec 16, 2005 5:21 pm
Completed: Fading Hearts, Infinite Game Works
Projects: Don't Save the World
Organization: Sakura River
Location: Canada
Contact:

Re: Jumping/returning to labels from screens

#2 Post by Counter Arts »

Ah... you should make another screen called map and use the screen "add" statement

Code: Select all


screen journal_open:
  ## Blah blah
  imagemap:
    
    hotspot (34,13,433,433) action ShowTransitent("mapScreen")

screen mapScreen:
  add map
  textbutton "Done":
    pos (10, 10)
    action Return()


Fading Hearts is RELEASED
http://www.sakurariver.ca

User avatar
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

Re: Jumping/returning to labels from screens

#3 Post by Evildumdum »

A useful little bit of code to use instead of Jump() is ui.callsinnewcontext()

It has a similar effect to the call function, in that it will return you to the spot you were at before when given the return function. Might not be exactly what you are after, but i always find it useful when using screens that i intend to return to.
"If at first you don't succeed, try hitting it with a shoe."

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Jumping/returning to labels from screens

#4 Post by Kia »

Rainvillain wrote:I imagine this has something to do with this menu screen being in front of the scene..?
correct, the screens are displayed on top of other images. you can add Hide(screen_name) to your button's action to fix it.
Rainvillain wrote:2. My second problem is that once I've clicked on load, save or preferences, and have been brought to their respective new screens, I can't seem to go back to my journal screen. The return buttons on each of those screens seem to return me directly to the game, skipping over the journal. I would prefer it return me to the journal, and then from the journal I would then return to the game.
try "show screen screen_name" instead of "ShowMenu"

User avatar
Rainvillain
Regular
Posts: 76
Joined: Thu Mar 05, 2015 11:27 am
Contact:

Re: Jumping/returning to labels from screens

#5 Post by Rainvillain »

Hey, thanks for the quick replies! The lemmasoft forums are the best. :)

Evildumdum:
Thanks for sharing us.callsinnewcontext("") with me! It seems to work really well for calling my map label! Thanks! Is there a way to use it to call screens as well? I tried doing:

Code: Select all

hotspot (1107,505,172,66) action ui.callsinnewcontext("preferences")
But clicking on the preferences hotspot in game caused me an error saying "could not find label 'preferences'", (which I understand since 'preferences isn't a label). So is there a way to make it call a screen too?

Counter Arts:
Thanks for telling me about the add statement but I seem to still be having an error somewhere...
I did what you wrote (assumed you meant ShowTransient) but then I got the following error when I try clicking on the map within the journal:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 161, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 161, in <module>
    $ ui.interact()
  File "game/screens.rpy", line 263, in execute
    screen mapScreen:
  File "game/screens.rpy", line 263, in execute
    screen mapScreen:
  File "game/screens.rpy", line 264, in execute
    add map
Exception: Not a displayable: <built-in function map>

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

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 161, in script
    $ ui.interact()
  File "/Applications/renpy-6.99.8-sdk/renpy/ast.py", line 805, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "/Applications/renpy-6.99.8-sdk/renpy/python.py", line 1461, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/00gamemenu.rpy", line 161, in <module>
    $ ui.interact()
  File "/Applications/renpy-6.99.8-sdk/renpy/ui.py", line 277, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/Applications/renpy-6.99.8-sdk/renpy/display/core.py", line 2436, in interact
    scene_lists.replace_transient()
  File "/Applications/renpy-6.99.8-sdk/renpy/display/core.py", line 727, in replace_transient
    self.remove(layer, tag)
  File "/Applications/renpy-6.99.8-sdk/renpy/display/core.py", line 1014, in remove
    self.hide_or_replace(layer, remove_index, "hide")
  File "/Applications/renpy-6.99.8-sdk/renpy/display/core.py", line 938, in hide_or_replace
    d = oldsle.displayable._hide(now - st, now - at, prefix)
  File "/Applications/renpy-6.99.8-sdk/renpy/display/screen.py", line 430, in _hide
    self.update()
  File "/Applications/renpy-6.99.8-sdk/renpy/display/screen.py", line 565, in update
    self.screen.function(**self.scope)
  File "game/screens.rpy", line 263, in execute
    screen mapScreen:
  File "game/screens.rpy", line 263, in execute
    screen mapScreen:
  File "game/screens.rpy", line 264, in execute
    add map
  File "/Applications/renpy-6.99.8-sdk/renpy/sl2/sldisplayables.py", line 352, in sl2add
    d = renpy.easy.displayable(d, scope=scope)
  File "/Applications/renpy-6.99.8-sdk/renpy/easy.py", line 92, in displayable
    raise Exception("Not a displayable: %r" % (d,))
Exception: Not a displayable: <built-in function map>

Darwin-15.2.0-x86_64-i386-64bit
Ren'Py 6.99.8.959
imagebuttons 0.0
From what I can tell the error seems to have to do with the "add map" part. The "map.png" file is in the images folder of my project. Any thoughts on what I'm doing wrong?

Kia:
Thanks for the help. Could you use "show screen screen_name" in an example for me? I tried variations on the following and it didn't work:

Code: Select all

hotspot (1107,505,172,66) action show screen preferences
I kept getting errors like:

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 253: u'show' is not a keyword argument or valid child for the hotspot statement.
    hotspot (1107,505,172,66) action show screen preferences
                                         ^

Ren'Py Version: Ren'Py 6.99.8.959
I imagine I'm just not writing out the whole hotspot line correctly...

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

Re: Jumping/returning to labels from screens

#6 Post by philat »

Somebody really ought to sticky this somewhere in the documentation for ShowMenu: 99.9% chance that this is not what you are looking for!!!1!!!111!

Use Show. If you want to make it so that you can't interact with anything but the screen shown, set modal to True.

Calling labels from screens is also generally not a great idea. Jump to them and call/show the screen at the end of the label.

Code: Select all

screen journal_icon:
    imagebutton auto "house_%s.png" action Show("journal_open") xpos 1100 ypos 510 focus_mask True

label fullmap:
    hide screen journal_open
    scene map
    $ renpy.pause ()
    show screen journal_open

Post Reply

Who is online

Users browsing this forum: No registered users