Returning to point where you left..

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.
Message
Author
User avatar
Bartulisica
Regular
Posts: 93
Joined: Sun Aug 30, 2015 5:11 am
Organization: ArizonaIdentities
Location: Croatia
Discord: ArizonaIdentities
Contact:

Returning to point where you left..

#1 Post by Bartulisica »

This topics title is a bit dumb, i know. But, I don't know how to describe it better. :D
Anyway, I want to make a shop label that can be jumped to at anytime in game. Everything works so far with a button that jumps to shop label. However, the problem is returning to the point where you left. Is it possible to return to the same place after you are done with shopping?
If not, do you have any ideas what's the next best thing?
I guess this could be done with screens, but I made the shop as a label because it's big and alot of things happen there (randomised responses, description for every item as dialogue, etc...). So, I'd like to keep it as a label.
- ArizonaIdentities

User avatar
Bartulisica
Regular
Posts: 93
Joined: Sun Aug 30, 2015 5:11 am
Organization: ArizonaIdentities
Location: Croatia
Discord: ArizonaIdentities
Contact:

Re: Returning to point where you left..

#2 Post by Bartulisica »

One more thing about the shop...
When you click on item it offers dialogue, and menu so you can choose if you want to buy the item or no. After that choice shop just restarts so you can buy something else. Problem here is that music restarts as well. Is there a way I can restart the shop screen without restarting the music? (I'm using jump to label, as I said in the last post)
- ArizonaIdentities

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Returning to point where you left..

#3 Post by trooper6 »

This is all part of the documentation. Have you read it yet? If you haven't read the Renpy documentation you really should!
http://www.renpy.org/doc/html/label.html#call-statement

Rather than jumping to your label, call your label. If you call the label, a return at the end of that label will send you back where you called from.

Compare Example A:

Code: Select all

label start:
    "You are starting here." #1
    jump block_b #2
    "Welcome back" #3
    jump end
    
label block_a:
    "You are in block a." #4
    return
    
label block_b:
    "You are in block b." #5
    return
    
label end:
    "Game over." #6
    return
With Example B:

Code: Select all

label start:
    "You are starting here." #1
    call block_b #2
    "Welcome back" #3
    jump end
    
label block_a:
    "You are in block a." #4
    return
    
label block_b:
    "You are in block b." #5
    return
    
label end:
    "Game over." #6
    return
In example A. You start at line #1, at line #2 you jump to #5. The return in block b sends you back where you called from. Since there are no calls on the stack, the game ends.

In Example B. You start at line #1, at line #2, you call to #5. The return in block B sends you back where you called from...so you return to line #3....then you jump to the end and get your game over line at #6. That return is the final return that ends the game.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Returning to point where you left..

#4 Post by trooper6 »

Bartulisica wrote:One more thing about the shop...
When you click on item it offers dialogue, and menu so you can choose if you want to buy the item or no. After that choice shop just restarts so you can buy something else. Problem here is that music restarts as well. Is there a way I can restart the shop screen without restarting the music? (I'm using jump to label, as I said in the last post)
Really depends on how you are doing your code. You'd have to post it.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Bartulisica
Regular
Posts: 93
Joined: Sun Aug 30, 2015 5:11 am
Organization: ArizonaIdentities
Location: Croatia
Discord: ArizonaIdentities
Contact:

Re: Returning to point where you left..

#5 Post by Bartulisica »

I read documentation when I need it, but it's a bit confusing and I can't get the right answers, anyway I'll read it more thoroughly!
Thanks once again.

About that code for music..

Code: Select all

label shop_screen:
        scene shop
        play music "Music/Shop_music.mp3"
Starts with that, and gives you the imagemap with multiple choices. After every choice it just jumps back to shop_screen.
- ArizonaIdentities

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Returning to point where you left..

#6 Post by trooper6 »

Off the top of my head, the two things that come to mind to fix your music problem would be:

1) Jump not to the label, but to a point after you play the music. Could you post more of the code? Is the imagemap on a screen? If you post the whole label's code it might be possible to find a way to jump to a point after the music code.

2) The second possibility might be to use some sort of if statement. In other words, if the music is playing, then don't replay. If it isn't playing play it. Let go and look up the documentation on Audio and experiment. http://www.renpy.org/doc/html/audio.html
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Returning to point where you left..

#7 Post by trooper6 »

So. I'm going to post my process on the if statement so that you can perhaps learn how I did this...so that you can do it yourself.

I went to the Audio page that I linked above and started looking at the functions. I notice the function: get_playing
http://www.renpy.org/doc/html/audio.htm ... et_playing

This function says: "If the given channel is playing, returns the playing file name. Otherwise, returns None."

So the idea would be to check to see if the shop_music is playing...if it isn't then play it...if it is...then don't play it.

Code: Select all

label shop_screen:
    if renpy.music.get_playing(channel='music') != "Music/Shop_music.mp3":
        play music "Music/Shop_music.mp3"
    "Here you are in the shop."
    return
This works. I highly recommend doing experimentation like I did. Trying it out yourself ends up making you a stronger coder.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Bartulisica
Regular
Posts: 93
Joined: Sun Aug 30, 2015 5:11 am
Organization: ArizonaIdentities
Location: Croatia
Discord: ArizonaIdentities
Contact:

Re: Returning to point where you left..

#8 Post by Bartulisica »

I'm experimenting all the time, but I don't know some things yet, so I'm checking documentation but I can't find what I'm looking for, often.
Thanks for solving this.. I didn't want to put my whole code here, because there is a lot of story in it already.
- ArizonaIdentities

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Returning to point where you left..

#9 Post by Onishion »

Yeah, Trooper's way of doing things is a good one, but just for due dilligence, the other option he hinted at would work more like this:

Code: Select all

label EnterShop:
    scene shop
    play music "Music/Shop_music.mp3"
    #you can put anything here that you only want to happen once, like the owner welcoming the player in or something
label Shop:
    menu:
        "Buy stuff":
            #stuff is bought
        #more shopping options
        "Exit":
            return
    jump Shop
Then you can just "call EnterShop", it'll do you that label, do all those things once, and then fall through to the "Shop" label, do all that stuff, and assuming you don't exit, it will kick back to the Shop label when it reaches the end, and keep repeating that until you hit exit, which will return you to where you called from.

Another method you can use, if you don't want to have a ton of labels, is:

Code: Select all

label EnterShop:
    scene shop
    play music "Music/Shop_music.mp3"
    #you can put anything here that you only want to happen once, like the owner welcoming the player in or something
    $ Count = 1
    while Count: #this will loop so long as the Count variable is not 0, you can use any variable you like, so long as you make it not-zero first
        menu:
            "Buy stuff":
                #stuff is bought
            #more shopping options
            "Exit":
                $ Count = 0 #this breaks the loop, kicking it down to the return statement.
    return
I use while loops like that from time to time to keep simple menu options going within other situations, they can be pretty handy.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Returning to point where you left..

#10 Post by trooper6 »

Onishion's first set of code can be simplified by giving the menu a name, so you don't need a second label. Like so:

Code: Select all

label EnterShop:
    scene shop
    play music "Music/Shop_music.mp3"
    #you can put anything here that you only want to happen once, like the owner welcoming the player in or something
    menu shop_m:
        "Buy stuff":
            #stuff is bought
        #more shopping options
        "Exit":
            return
    jump shop_m
I didn't put this code up because I really wasn't sure if Bartilusica was using a menu...it seems like she was using a screen...but she wouldn't post any code, so actual help for option A I couldn't really do.

Bartilusica, a piece of advice on experimentation, when I am experimenting on a specific issue, I don't do it in my actual project. I create a fresh project that only has the element I'm trying to test. Once I get it working in the stripped down test project, then I work on integrating it into the actual project.

Lastly, you said you don't want to post your code because it has story in it, but we are not going to be able to help you most effectively if we don't see your code. For example, if you are using a menu, then the Option A code above would work...but if you are using a screen...that code won't be effective. But what would be effective would depend on how you are accessing that screen.

You have to share a bit more to get the most effective responses.
Last edited by trooper6 on Sun Oct 04, 2015 5:49 pm, edited 1 time in total.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Returning to point where you left..

#11 Post by Onishion »

Onishion's first set of code can be simplified by giving the menu a name, so you don't need a second label. Like so:
Also true, forgot about that bit. So many different ways to do stuff. ;) Remember that the jump shop_m needs to be back on the same indent as the "menu" though, otherwise it will complain that it's not a menu item.
Bartilusica, a piece of advice on experimentation, when I am experimenting on a specific issue, I don't do it in my actual project. I create a fresh project that only has the element I'm trying to test. Once I get it working in the stripped down test project, then I work on integrating it into the actual project.

Lastly, you said you don't want to post your code because it has story in it, but we are not going to be able to help you most effectively if we don't see your code. For example, if you are using a menu, then the Option A code above would work...but if you are using a screen...that code won't be effective. But what would be effective would depend on how you are accessing that screen.
True. In my case, I just use a "test" room in the game that I have set to be the default starting area until I'm ready to launch, and that way I can add all sorts of potentially game breaking stuff, try it out, and then just shift where it is in the code, without having to change projects.

For posting code, if you don't want story spoilers I would suggest just copy-pasting the code and deleting out or replacing any specific language you're using.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Returning to point where you left..

#12 Post by trooper6 »

Onishion wrote:
Onishion's first set of code can be simplified by giving the menu a name, so you don't need a second label. Like so:
Also true, forgot about that bit. So many different ways to do stuff. ;) Remember that the jump shop_m needs to be back on the same indent as the "menu" though, otherwise it will complain that it's not a menu item.
Fixed! Thanks for catching that!
Onishion wrote: For posting code, if you don't want story spoilers I would suggest just copy-pasting the code and deleting out or replacing any specific language you're using.
Indeed. You can replace "And then she grabbed the knife from Chad!" with "Blah, blah, blah."
But lots of secrecy will make it hard to get effective help. If secrecy is more important that posting your code, but you still need extensive help, you might want to commission a programmer in the recruitment thread and then you can have them sign an NDA.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Bartulisica
Regular
Posts: 93
Joined: Sun Aug 30, 2015 5:11 am
Organization: ArizonaIdentities
Location: Croatia
Discord: ArizonaIdentities
Contact:

Re: Returning to point where you left..

#13 Post by Bartulisica »

Wow, I didn't see that you guys continued giving advices untill now.
Everything works fine, thanks a bunch, fixed that music problem with trooper's renpy.get_music. Works like a charm, I did something like that with inventory button (renpy.get_screen), but I didn't know it works for music as well. :D

As for suggestion that I use fresh projects to try out stuff.. I am doing that, but sometimes it's a small thing, one line or so, and I'm too lazy to make a new project with the same situation, just to try out a detail. So I do it in the actual script I'm working on.

Now, I can't get one more thing right, I looked in documentation but I can't find the actual example or description on how to use
call label in an imagebutton. I doesn't take "action call shop_screen" or "action Call ("shop_screen")".. I'm not sure what's the call command here..
- ArizonaIdentities

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Returning to point where you left..

#14 Post by trooper6 »

renpy.get_music is in the documentation.

As for calling a screen, you can't do it. If you look at the screen actions page: http://www.renpy.org/doc/html/screen_actions.html
you'll notice there are six control actions: Hide, Jump, NullAction, Return, Show, and ShowTransient. There is no call.

Do you absolutely need to call the screen? Why? Here is a tester that show three different ways to get a screen from a screen.
The screens are also more advanced. Create a tester and put this code in it. Then study the code. See if any of this inspires you:

Code: Select all

screen mainBattle(char, enemy):
    frame align (0.12, 0.12):
        vbox xalign 0.05:
            text "Battle!"
            text "-----"
            text "YOU: [char.hp]/[char.maxHP] HP"
            text "ENEMY: [enemy.hp]/[enemy.maxHP] HP"
            textbutton "Fight in new context" action ui.callsinnewcontext("choosetest", char)
            textbutton "Fight ShowTransient" action ShowTransient("choose_trans", char=char)
            textbutton "Fight Show" action Show("choose_show", char=char)
            textbutton "End Fight" action [SetVariable("tempSkill", None), Hide("mainBattle")]
            if tempSkill:
                text "Result: [tempSkill.name]"

screen choose_new(char):
    frame:
        align(0.5,0.5)
        vbox:
            text "Choose your action!"
            text "-----"
            for i in char.skills:
                textbutton "[i.name]" action [SetVariable("tempSkill", i), Return()]
            
screen choose_trans(char):
    modal True
    frame:
        align(0.5,0.5)
        vbox:
            text "Choose your action!"
            text "-----"
            for i in char.skills:
                textbutton "[i.name]" action [SetVariable("tempSkill", i), Return()]
            
screen choose_show(char):
    modal True #This is only needed for the various show versions, not needed for the call version
    frame:
        align(0.5,0.5)
        vbox:
            text "Choose your action!"
            text "-----"
            for i in char.skills:
                textbutton "[i.name]" action SetVariable("tempSkill", i)
            textbutton "Close Screen" action Hide("choose_show")
            
init python:
    class Char():
        def __init__(self, name, hp, mhp, skills):
            self.name = name
            self.hp = hp
            self.maxHP = mhp
            self.skills = skills 
    class Skill():    
        def __init__(self, name, number):
            self.name = name
            self.number = number
            
label choosetest(char):
    call screen choose_new(char)
    return

default fight = Skill("Fight", 12)
default defend = Skill("Defend", 14)
default talk = Skill("Talk", 16)
default hero = Char("Hero", 10, 10, [fight, defend, talk])
default villain = Char("Villain", 12, 12, [fight, defend, talk])
default tempSkill = None
    
# The game starts here.
label start:
    scene black
   
    "This tester looks at three different ways of accessing a screen from a screen."
    show screen mainBattle(hero, villain)
    
    "Here is a Battle screen. There are three buttons here. First try 'Fight from new context.' 
     When you click it, you will be brought to a new screen and everything else disappears. Click on 
     one of the choices on that second screen. When you click one of those buttons, you will come back 
     to where you were before (Basically that click doesn't count as an interaction in the main game's 
     context, because you are in a new temporary context). But note, This text will still be here. 
     After you've done that, click anywhere to advance the text."
    
    "Note one more thing about calling in new context: with that command you can only call a label not a screen, 
     so you have to have a label that calls your screen. It is a bit convoluted, but gets the job done. Click onward."
    
    "Now click on Fight with ShowTransient. Because the screen is modal you can't click on anything else 
     while that screen is up. Try clicking outside of the new screen. Also note that unlike call in new context 
     everything else doesn't disappear (because you are not in a new context). Also note this text stays. Click a button."
    
    "Notice that clicking a button using ShowTransient causes the screen to disappear (because that is what ShowTransient does) 
     and advances the text as well--because the buttons on this screen include the Return() action, which is an interaction. 
     Okay click somewhere to advance the text."
    
    "Now here is one more option for a screen from a screen. That is just the regular Show. Click on that button. Because 
     the screen is modal, you can't advance the game by clicking anywhere else, go ahead and try. Now try clicking the buttons.  
     On this screen I got rid of the Return() action in the buttons, so you can click on them but it doesn't advance anything. 
     Click close screen to close the screen. It also doesn't have a Return() action so it won't advance the game. So after
     you do that, click to move on."
    
    "That is the end of this tester. Click end fight."
    "Tester Over."
    
    return
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Bartulisica
Regular
Posts: 93
Joined: Sun Aug 30, 2015 5:11 am
Organization: ArizonaIdentities
Location: Croatia
Discord: ArizonaIdentities
Contact:

Re: Returning to point where you left..

#15 Post by Bartulisica »

I saw there is no call, that's why I asked on forum. As I mentioned before, I'd like to return to the screen from which I left before, so you suggested call label. But I want to leave the first label by button, and when called label is done, I want to return to the place where I left? That possible.

I'll test your code a bit later.. when my coffee is done. :D
- ArizonaIdentities

Post Reply

Who is online

Users browsing this forum: Ocelot