Question about renpy.jump_out_of_context

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
chewpower
Regular
Posts: 36
Joined: Mon Feb 11, 2013 11:08 pm
Contact:

Question about renpy.jump_out_of_context

#1 Post by chewpower »

Hello, all ^^ In my game, there is a map screen where player can go to certain places. I show this screen with ui.callsinnewcontext("label_where_map_screen_is_called") and then inside the label I just do call screen("the_map_screen").

The map uses hotspots which returns something to be evaluated in the "label_where_map_screen_is_called", something like:

Code: Select all

if _return == "place1":
    jump place1_label
and so on.

I've been using this code for a while but I never noticed the error it causes. Whenever I save the game, the loaded game isn't right. It is always at the point BEFORE the player can use the map. So I assume there's something wrong with my code at that point. So I change the code like this.

Code: Select all

if _return == "place1":
    $ renpy.jump_out_of_context("place1_label")
And this fixes the save/load issue (when I save and load, it's at the right point of the game).

The problem is, I don't know why.

I've been reading a bit here and there about context, about what ui.callsinnewcontext does, about what renpy.jump_out_of_context is, but I still don't get it. Can someone tell me what's going on? Is this the right fix or will there be any problem that I should expect next? Thank you all...
I'm sorry if I'm too stupid, but I can't learn to walk on my own

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Question about renpy.jump_out_of_context

#2 Post by apricotorange »

Ren'Py maintains a stack of objects called "contexts". Your game normally runs in the primary context. When you call something like ShowMenu or ui.callsinnewcontext, it pushes a secondary context onto the stack (preserving the state of the primary context). renpy.jump_out_of_context pops a context off the stack.

As you have discovered, Ren'Py savegames only tracks state in the primary context; the secondary contexts are ignored. This allows, for example, opening a menu to save the game without worrying about the menu popping back up when the game is loaded. On the other hand, it means that you want to be very careful about how you use ui.callsinnewcontext. It's occasionally useful to do something like show an information screen, but it's not a good way to display an imagemap where the player chooses between different paths. In your case, it sounds like you should just be using Jump().

User avatar
chewpower
Regular
Posts: 36
Joined: Mon Feb 11, 2013 11:08 pm
Contact:

Re: Question about renpy.jump_out_of_context

#3 Post by chewpower »

Thank you, apricotorange! I understand better now. I need to learn a lot more about everything else it seems...
apricotorange wrote:It's occasionally useful to do something like show an information screen, but it's not a good way to display an imagemap where the player chooses between different paths. In your case, it sounds like you should just be using Jump().
The reason I call it with ui.callsinnewcontext is that so I can use Return button, which is just another hotspot with action Return() on it. This provides option for players if they suddenly change their mind (about going somewhere) and return to the game. Another information screen also has Return button so I think it'd be great if the map has it too.
I'm sorry if I'm too stupid, but I can't learn to walk on my own

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Question about renpy.jump_out_of_context

#4 Post by apricotorange »

Hmm... I'm not really understanding the structure of your game, but if it makes sense to you, then it's probably fine.

Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Dark79, Google [Bot], Qchosis