Map where you cannot go to the same place multiple times

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
CephalonKet
Newbie
Posts: 7
Joined: Sun Apr 28, 2024 12:27 pm
Contact:

Map where you cannot go to the same place multiple times

#1 Post by CephalonKet »

Hey everyone. New here and to Ren'py coding so bear with me.

I would like to implement a map at certain points in my game. Now I figured out how to do this with the helpful code from other users, but what I need now is:

When you go to the map, you have the option to go to places where you hover over them and there's buttons. I want every time you return from the place you were on for the place to not be accessible again, until no places are accessible anymore and it triggers the next event which will take you somewhere else, for example to your room for the night.

I know how to remove choices with a menu choice, but not how to do it with buttons. Any assistance?
Here is my code in one script file(most of it taken directly from other users that shared it):

Code: Select all

label call_mapUI:
    call screen MapUI

screen MapUI:
    add "map/bg map.jpg"

    imagebutton:
        xpos 618
        ypos 570
        idle "map/house1_idle.png"
        hover "map/house1_hover.png"
        action Jump("house1_pressed")
        
    imagebutton:
        xpos 596
        ypos 165
        idle "map/house2_idle.png"
        hover "map/house2_hover.png"
        action Jump("house2_pressed")
Second code:

Code: Select all

label map:
    jump call_mapUI

label house1_pressed:
    scene bg classroom
    "House 1 was pressed!"
    jump call_mapUI

label house2_pressed:
    "House 2 was pressed!"
    jump call_mapUI
Obviously with the above code, it loops and keeps taking me back to the map right now. How do I implement that it checks where I've been, makes them inaccessible, and then once everywhere has been visited, triggers my next scene?

Thank you very much for your time.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1009
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Map where you cannot go to the same place multiple times

#2 Post by m_from_space »

CephalonKet wrote: Tue May 07, 2024 9:47 pm I know how to remove choices with a menu choice, but not how to do it with buttons. Any assistance?
You just have to save what was visited either in a single variable or a list or whatnot and then check for that condition inside of the screen.

An example (which also works for imagebuttons in the same way):

Code: Select all

# the list of visited places, we will just store strings inside of here
default visited = []

screen myscreen():
    vbox:
        # this button will disappear when you click it / visit the house
        if "house1" not in visited:
            textbutton "Visit the house!" action Jump("house_one")

        # this button instead will just be deactivated after visiting the house
        textbutton "Visit the house as well!":
            action Jump("house_one")
            sensitive "house1" not in visited

label house_one:
    $ visited.append("house1")
    "Welcome to my home!"
    # ...

CephalonKet
Newbie
Posts: 7
Joined: Sun Apr 28, 2024 12:27 pm
Contact:

Re: Map where you cannot go to the same place multiple times

#3 Post by CephalonKet »

m_from_space wrote: Wed May 08, 2024 8:48 am
CephalonKet wrote: Tue May 07, 2024 9:47 pm I know how to remove choices with a menu choice, but not how to do it with buttons. Any assistance?
You just have to save what was visited either in a single variable or a list or whatnot and then check for that condition inside of the screen.

An example (which also works for imagebuttons in the same way):
Hi, thank you for your response! Unfortunately I'm too green to be able to implement your example in my own code. I tried copy pasting it exactly for example and nothing is changing. I don't understand how variables work to adapt it to my code :(. I appreciate any help.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1009
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Map where you cannot go to the same place multiple times

#4 Post by m_from_space »

CephalonKet wrote: Wed May 08, 2024 11:07 am Hi, thank you for your response! Unfortunately I'm too green to be able to implement your example in my own code. I tried copy pasting it exactly for example and nothing is changing. I don't understand how variables work to adapt it to my code :(. I appreciate any help.
Can you show me your relevant code after trying to adapt it? It's probably more helpful to see the mistakes in your code.

CephalonKet
Newbie
Posts: 7
Joined: Sun Apr 28, 2024 12:27 pm
Contact:

Re: Map where you cannot go to the same place multiple times

#5 Post by CephalonKet »

m_from_space wrote: Wed May 08, 2024 2:39 pm
CephalonKet wrote: Wed May 08, 2024 11:07 am Hi, thank you for your response! Unfortunately I'm too green to be able to implement your example in my own code. I tried copy pasting it exactly for example and nothing is changing. I don't understand how variables work to adapt it to my code :(. I appreciate any help.
Can you show me your relevant code after trying to adapt it? It's probably more helpful to see the mistakes in your code.
Okay so I have two rpy files I'm working with based on the tutorials I've followed.

For one I have the code like this (I called it custom_screens.rpy based on the tutorial):

Code: Select all

label call_mapUI:
    call screen MapUI
default visited = []
screen MapUI():
    add "map/bg map.jpg"
    vbox:
        if "house1_pressed" not in visited:
            imagebutton:
                xpos 618
                ypos 570
                idle "map/house1_idle.png"
                hover "map/house1_hover.png"
                action Jump("house1_pressed")
            
            imagebutton:
                xpos 596
                ypos 165
                idle "map/house2_idle.png"
                hover "map/house2_hover.png"
                action Jump("house2_pressed")
                sensitive "house1_pressed" not in visited

label house_one:
    $ visited.append("house1_pressed")
    "welcome to my home"

"hello"
And for my main script file:

Code: Select all

label map:
    jump call_mapUI

label house1_pressed:
    scene bg classroom
    "House 1 was pressed!"
    jump call_mapUI

label house2_pressed:
    "House 2 was pressed!"
    jump call_mapUI
This code is probably a mess right now, I tried a lot of trial and error, and now it's at a point where it's stuck in a loop again.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1009
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Map where you cannot go to the same place multiple times

#6 Post by m_from_space »

CephalonKet wrote: Wed May 08, 2024 6:34 pm For one I have the code like this (I called it custom_screens.rpy based on the tutorial):
In general your code looks fine regarding my suggestions. But two issues:

1) The Jump("house1_pressed") should also have a label with that name, you just used my label name from the example which is called "house_one", but never jump there. You have to decide on a single name, otherwise it cannot jump there. My code examples never use all your own variable names, you have to take care of that yourself. ;)

So this is correct for your game, but I would advice you to not use "house1_pressed" as both the label name and the string to check if it was already pressed. That's why I used the label name "house_one" and the string "house1" to not confuse you:

Code: Select all

label house1_pressed:
    $ visited.append("house1_pressed")
    scene bg classroom
    "House 1 was pressed!"
    jump call_mapUI
2) The second button should be out-dented though, it shouldn't be inside the if-block, otherwise it will disappear as well when visiting the house. I guess you just use the two variants to figure out which one you like better.

Code: Select all

        if "house1_pressed" not in visited:
            imagebutton:
                xpos 618
                ypos 570
                idle "map/house1_idle.png"
                hover "map/house1_hover.png"
                action Jump("house1_pressed")
            
            <-- outdent this one block
            imagebutton:
                xpos 596
                ypos 165
                idle "map/house2_idle.png"
                hover "map/house2_hover.png"
                action Jump("house2_pressed")
                sensitive "house1_pressed" not in visited
This code is probably a mess right now, I tried a lot of trial and error, and now it's at a point where it's stuck in a loop again.
The loop has nothing to do with my suggestions and the way you implemented them. It's because you jump to label "call_mapUI", which calls a screen, that then waits for user interaction, jumping to another label, which will call the screen again later on. What exactly do you expect when not a loop?

CephalonKet
Newbie
Posts: 7
Joined: Sun Apr 28, 2024 12:27 pm
Contact:

Re: Map where you cannot go to the same place multiple times

#7 Post by CephalonKet »

m_from_space wrote: Thu May 09, 2024 11:44 am The loop has nothing to do with my suggestions and the way you implemented them. It's because you jump to label "call_mapUI", which calls a screen, that then waits for user interaction, jumping to another label, which will call the screen again later on. What exactly do you expect when not a loop?
Hi, thank you again for your answer. When I put the code as you say, the buttons don't disappear after I click them, and I can just keep going to the same two locations. The only way to stop that is if I remove the 'jump call_mapUI' on say, the second house.

So my code right now doesn't have any difference to how it started. I lack the experience to understand how I need to write it to stop the loop and make the buttons disappear. My code right now:

On script.rpy:

Code: Select all

label map:
    jump call_mapUI

label house1_pressed:
    scene bg classroom
    "House 1 was pressed!"
    jump call_mapUI

label house2_pressed:
    "House 2 was pressed!"
    jump call_mapUI    
    
##below does not work, as it never exits the map loop
label nextscene:
    scene black 
    show mc idle at left
e "Welcome back"
on custom_screens.rpy:

Code: Select all

label call_mapUI:
    call screen MapUI
default visited = []
screen MapUI():
    add "map/bg map.jpg"
    vbox:
        if "house1_pressed" not in visited:
            imagebutton:
                xpos 618
                ypos 570
                idle "map/house1_idle.png"
                hover "map/house1_hover.png"
                action Jump("house1_pressed")
            
        imagebutton:
            xpos 596
            ypos 165
            idle "map/house2_idle.png"
            hover "map/house2_hover.png"
            action Jump("house2_pressed")
            sensitive "house1_pressed" not in visited

label house_1_pressed:
    $ visited.append("house1_pressed")
    scene bg classroom
    "House 1 was pressed!"
    jump call_mapUI 
    
#below also does not work, put there for testing
"hello"
The buttons stay whenever I go back to the map, I need for example, for house one to be unclickable after visiting it once, which is not happening right now with my code. I also need for the code to 'see' when both houses are visited in order to jump to the next label.

Thank you for your help!

jeffster
Veteran
Posts: 436
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Map where you cannot go to the same place multiple times

#8 Post by jeffster »

CephalonKet wrote: Thu May 09, 2024 1:39 pm On script.rpy:

Code: Select all

label map:
    jump call_mapUI

label house1_pressed:
    scene bg classroom
    "House 1 was pressed!"
    jump call_mapUI

label house2_pressed:
    "House 2 was pressed!"
    jump call_mapUI    
    
##below does not work, as it never exits the map loop
label nextscene:
    scene black 
    show mc idle at left
e "Welcome back"
on custom_screens.rpy:

Code: Select all

label call_mapUI:
    call screen MapUI
default visited = []
screen MapUI():
    add "map/bg map.jpg"
    vbox:
        if "house1_pressed" not in visited:
            imagebutton:
                xpos 618
                ypos 570
                idle "map/house1_idle.png"
                hover "map/house1_hover.png"
                action Jump("house1_pressed")
            
        imagebutton:
            xpos 596
            ypos 165
            idle "map/house2_idle.png"
            hover "map/house2_hover.png"
            action Jump("house2_pressed")
            sensitive "house1_pressed" not in visited

label house_1_pressed:
    $ visited.append("house1_pressed")
    scene bg classroom
    "House 1 was pressed!"
    jump call_mapUI 
    
#below also does not work, put there for testing
"hello"
The buttons stay whenever I go back to the map, I need for example, for house one to be unclickable after visiting it once, which is not happening right now with my code. I also need for the code to 'see' when both houses are visited in order to jump to the next label.

Thank you for your help!
First of all you need to learn how to use labels, jumps and calls.
https://renpy.org/doc/html/label.html

In the code you posted above clicking the 1st house jumps to "label house1_pressed".

That label does not record that you visited "house1":

Code: Select all

label house1_pressed:
    scene bg classroom
    "House 1 was pressed!"
    jump call_mapUI
Therefore that button remains clickable.

Another label is "house_1_pressed", but its code doesn't run because clicking the button doesn't jump there.
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

CephalonKet
Newbie
Posts: 7
Joined: Sun Apr 28, 2024 12:27 pm
Contact:

Re: Map where you cannot go to the same place multiple times

#9 Post by CephalonKet »

Figured it out. Here is what I did:

On my custom_screens.rpy:

Code: Select all

default visited = 0
default button_enabled_flag = True
default button_enabled_flag2 = True
label call_mapUI:
    
    call screen MapUI


screen MapUI:
        add "map/bg map.jpg"
        vbox:
            imagebutton: 
                sensitive button_enabled_flag 
                xpos 618
                ypos 570
                idle "map/house1_idle.png"
                hover "map/house1_hover.png"
                action Jump("house1_pressed")
            
            imagebutton:
                sensitive button_enabled_flag2 
                xpos 596
                ypos 165
                idle "map/house2_idle.png"
                hover "map/house2_hover.png"
                action Jump("house2_pressed")
On my main script.rpy:

Code: Select all

label map:
    if visited == 2: 
        jump nextscene
    else:
        jump call_mapUI
    
label house1_pressed:
    scene bg classroom
    "House 1 was pressed wow!"
    $ button_enabled_flag = False
    $ visited += 1
    jump map

label house2_pressed:
    scene bg room
    "House 2 was pressed wow!"
    $ button_enabled_flag2 = False
    $ visited += 1
    jump map


label nextscene:
    scene black 
    show mc idle at left
    e   "Welcome back"

giorgi1111
Newbie
Posts: 14
Joined: Sat May 04, 2024 10:40 pm
Contact:

Re: Map where you cannot go to the same place multiple times

#10 Post by giorgi1111 »

When you had default visited = [] you must updated it in imagebutton action. If jumped house Visited = [house]. Imagebutton: if house not in visited action jump house ((setvariable visited house) i dont exactly know how update list) else action jump somewhere or notify you allready visited house

Post Reply

Who is online

Users browsing this forum: No registered users