Page 1 of 1

Showing a screen or another one after labels or screens

Posted: Sun May 26, 2019 5:57 pm
by Adrian_DVL
Say I'm developing a sandbox-like game in which there are two different maps. I've made these two maps as two different screens, each one with its hotspots and links to labels.

Then I have a loop label that repeats itself during the game to show the map whenever an event (label) is finished or a menu (another screen) is closed, by calling the screen, just like this:

Code: Select all

label showmap:
	if (renpy.music.is_playing('music')):
        	pass
        else:
                play music "sfx/map.mp3" loop
        call screen map1
The screen called by that label is the first map. The thing is that my game was intended to have just one map at first, but now I made a second one.

So my problem is that I literally don't know how I can call (or show, I guess I could make do with that) one map or the other after a certain event or after closing menus (which are also screens). I've tried different functions as well as the typical statements with no luck.

So I made another label to call the second map from there, so that I can jump to one label or another after the different events and problem solved. But I still have the same problem with the menus and some hotspots that are commom to both maps: I don't know how to call one map or another (or jump to one label or another) depending on which one was running before the menu or the hotspot was called, or, in other words, I don't know how to jump to the label that was in charge before a new label was called.

I don't know if I made myself clear, but I hope someone can help me with this!

Re: Showing a screen or another one after labels or screens

Posted: Mon May 27, 2019 1:16 pm
by SONTSE
i think you should provide exact code you need to fix because usually there are no problem to make a switch between shown statements whatsoever.

Code: Select all

screen map_switch
    if condition:
        use map1
    else:
        use map2

Code: Select all

label mapswitch:
    if condition:
        call screen map1
    else:
        call screen map2
both approaches should work just fine

Re: Showing a screen or another one after labels or screens

Posted: Tue May 28, 2019 3:39 am
by Adrian_DVL
Lena_Borodach wrote:
Mon May 27, 2019 1:16 pm
i think you should provide exact code you need to fix because usually there are no problem to make a switch between shown statements whatsoever.

Code: Select all

screen map_switch
    if condition:
        use map1
    else:
        use map2

Code: Select all

label mapswitch:
    if condition:
        call screen map1
    else:
        call screen map2
both approaches should work just fine
That would be the correct approach if there were definite conditions to call one screen or another, but it's not the case. For instance, I have a hotspot that leads to a label that is accesible from both of the two maps wherever the state of the game is, and the player can go to that hotspot whenever they want to. When this label is finished, I'd like the game to call the map that was active BEFORE the hotspot was clicked. But I can't predict in which map will the player be at any moment of the game, in order to set conditions to call one screen or another...

Re: Showing a screen or another one after labels or screens

Posted: Tue May 28, 2019 5:21 am
by philat
Depends on how it's set up, but an easy way to is set a variable on showing a screen.

Code: Select all

default screen_to_show = "test1"

screen test1():
    on "show" action SetVariable("screen_to_show", "test1")
    # other stuff happens

screen test2():
    on "show" action SetVariable("screen_to_show", "test2")
    # other stuff happens
You can then use the variable to call the screen.

Code: Select all

$ renpy.call_screen(screen_to_show) # this takes the place of call screen map1, basically

Re: Showing a screen or another one after labels or screens

Posted: Tue May 28, 2019 7:59 am
by Adrian_DVL
philat wrote:
Tue May 28, 2019 5:21 am
Depends on how it's set up, but an easy way to is set a variable on showing a screen.

Code: Select all

default screen_to_show = "test1"

screen test1():
    on "show" action SetVariable("screen_to_show", "test1")
    # other stuff happens

screen test2():
    on "show" action SetVariable("screen_to_show", "test2")
    # other stuff happens
You can then use the variable to call the screen.

Code: Select all

$ renpy.call_screen(screen_to_show) # this takes the place of call screen map1, basically
I'm messing around with this and it definitely is helping me! From how I have the game set up, I have to recode the screens a lot though. But what I tried so far with the SetVariable action is working. Thank you so much!