Calling renpy.jump from function and some other questions.

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
allanon
Newbie
Posts: 15
Joined: Wed Apr 15, 2015 4:33 pm
Contact:

Calling renpy.jump from function and some other questions.

#1 Post by allanon » Wed Apr 15, 2015 4:44 pm

Hi, I am newbie in RenPy and python (I have started to learn it today), but I'm a little bit expirienced in programming.
So, the first question. I need to jump to label from function.

Simple function:

Code: Select all

init python:
    def Move(where):
        time += 5
        renpy.jump(where)
        return
Calling from label start:

Code: Select all

menu:
        "Go home":
            "You are going home"
            #$ Move("home")
And here comes the problem. If label home declared in label start, then everything is ok and function works, but if it declared separatly, RenPy just returns to title screen.
Is there a way to jump from function?

And second question: "Is there a way to change position on screen of choise menu?"

P.S. Sorry for my poor english.

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: Calling renpy.jump from function and some other question

#2 Post by trooper6 » Wed Apr 15, 2015 4:59 pm

I'm at work and can't give a bunch of detailed feedback (which always comes from me trying out code myself)...but I did notice something.

You shouldn't ever reach the return in your function because you jump away before you ever get to the return. When you have returned to the title screen that is because you didn't actually jump. So...ditch the return first off. Then let me think about the renpy jump when I get home and have a chance to play with code.
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

AlexCLD
Newbie
Posts: 24
Joined: Sun Mar 22, 2015 6:44 pm
Projects: Just a Number
Contact:

Re: Calling renpy.jump from function and some other question

#3 Post by AlexCLD » Wed Apr 15, 2015 5:26 pm

I'm a noob on Ren'py but I think that I can answer the second question.

Code: Select all

screen choice(items):

    window:
        style "menu_window"
        xalign 0.5
        yalign 0.5

        vbox:
            style "menu"
            spacing 2

            for caption, action, chosen in items:

                if action:

                    button:
                        action action
                        style "menu_choice_button"

                        text caption style "menu_choice"

                else:
                    text caption style "menu_caption"

init -2:
    $ config.narrator_menu = True

    style menu_window is default

    style menu_choice is button_text:
        clear

    style menu_choice_button is button:
        xminimum int(config.screen_width * 0.75)
        xmaximum int(config.screen_width * 0.75)
In screen.rpy you will find this code.

And here:

Code: Select all

    window:
        style "menu_window"
        xalign 0.5
        yalign 0.5
You can change the position of the choice menu.

0.5 means centered menu

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: Calling renpy.jump from function and some other question

#4 Post by trooper6 » Wed Apr 15, 2015 11:11 pm

Hello. So here is an example of what you wanted in a way that works when I run it:

Code: Select all

init -1 python:
    def move(where):
        global minutes #you need to mark this variable as global or it won't update the actual variable
        minutes += 5
        renpy.call(where) #by calling the label rather than jumping, it will go off where you asked it to go, then return here when finished.

# The game starts here.
label start:
    $ minutes = 0 #I think time is a reserved word...so I named your variable minutes instead
    
    menu choices: #I named your menu so you could jump back to it.
        "Where will you go?"
        "Go Home":
            "You are going home."
            $ move("home")
        "Go Shopping":
            "You are going shopping."
            $ move("shopping")
        "Go on a murder spree.":
            "You are going on a murder spree."
            $ move("murder")
        "Finish game.":
            jump end
    jump choices #I want this to be a loop where to keep coming back to the choices until you choose to end the game.
    
label end: #This ends the game
    "This game is done."
    "You have spent [minutes] mintues."
            
    return

#All of these labels are after the game ends so you jump to these labels from your menu and then return back to the menu    
label home:
    "Your home is very nice."
    "You have spent [minutes] mintues."
    return
    
label shopping:
    "You buy lots of things."
    "You have spent [minutes] mintues."
    return
    
label murder:
    "You murder a lot of orcs."
    "You have spent [minutes] mintues."
    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
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Calling renpy.jump from function and some other question

#5 Post by trooper6 » Wed Apr 15, 2015 11:21 pm

Now that above post works the way you asked. But looking at it...I would do it slightly differently.
So...why are you making a function? It seems the only reason is so you can increase the minutes variable. But I personally wouldn't want to do the updating of the minutes in the function...because then it takes the same amount of time to go to each place...and I'd rather different activities takes different amounts of time. And if you do that...you don't actually need a function at all.

Option 1) If the scenes for each of those options are not too long, you can just put all the information in the menu itself.

Code: Select all

# The game starts here.
label start:
    $ minutes = 0
    
    menu choices:
        "Where will you go?"
        "Go Home":
            $ minutes +=5
            "You are going home."
            "Your home is very nice."
            "You have spent [minutes] minutes."
        "Go Shopping":
            $ minutes +=10
            "You are going shopping."
            "Shopping is very fun."
            "You have spent [minutes] minutes."
        "Go on a murder spree.":
            $ minutes +=15
            "You are going on a murder spree."
            "You kill lots of orcs."
            "You have spent [minutes] minutes."
        "Finish game.":
            jump end
    jump choices
    
label end:
    
    "This game is done."
    "You have spent [minutes] mintues."
            
    return
On the other hand if each of these options are really, really long...you could make each its own label and then call that label in the menu, like so:

Code: Select all

label start:
    $ minutes = 0
    
    menu choices:
        "Where will you go?"
        "Go Home":
            "You are going home."
            call home
        "Go Shopping":
            "You are going shopping."
            call shopping
        "Go on a murder spree.":
            "You are going on a murder spree."
            call murder
        "Finish game.":
            jump end
    jump choices
    
label end:
    
    "This game is done."
    "You have spent [minutes] mintues."
            
    return
    
label home:
    $ minutes +=5
    "Your home is very nice."
    "You have spent [minutes] mintues."
    return
    
label shopping:
    $ minutes +=10
    "You buy lots of things."
    "You have spent [minutes] mintues."
    return
    
label murder:
    $ minutes +=15
    "You murder a lot of orcs."
    "You have spent [minutes] mintues."
    return
It just doesn't seem to me that you really need the function if all you are doing in that function is adding some minutes to your time variable.
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
allanon
Newbie
Posts: 15
Joined: Wed Apr 15, 2015 4:33 pm
Contact:

Re: Calling renpy.jump from function and some other question

#6 Post by allanon » Thu Apr 16, 2015 4:22 am

Thank you! I'll try your solution.
trooper6 wrote: It just doesn't seem to me that you really need the function if all you are doing in that function is adding some minutes to your time variable.
I'm just try to figure out, how it works. Of cource Move function is pointless now, but in the future, it should handle many conditions on location change, like PC stats change, calling random events, etc.

User avatar
allanon
Newbie
Posts: 15
Joined: Wed Apr 15, 2015 4:33 pm
Contact:

Re: Calling renpy.jump from function and some other question

#7 Post by allanon » Thu Apr 16, 2015 5:09 am

AlexCLD wrote: And here:

Code: Select all

    window:
        style "menu_window"
        xalign 0.5
        yalign 0.5
You can change the position of the choice menu.

0.5 means centered menu
Thank you! It is really so!

Post Reply

Who is online

Users browsing this forum: Google [Bot]