Ren'Py Quick question about jumps in Ren'Py....

SylvesterTemple

New Member
Sep 8, 2018
10
31
I'm going to try and explain this as best I can, so bare with me as I botch this; there's also going to be abysmal pseudocode here, but hopefully you'll understand....

Is it possible in Ren'Py to store a string as a variable, and then use a jump/goto instruction (call, maybe? I dunno - something to go to another scene!) to jump to the function stored in the variable?

Psuedo:

Code:
MainGameLoop:
rem Set TargetPerson and Room for start of Jump
    If TargetPerson = "Alice" and Room = "Bedroom" then JumpTarget$ = "AliceBedroom"
    If TargetPerson = "Betty" and Room = "Bedroom" then JumpTarget$ = "BettyBedroom"
    
rem Add TimeOfDay to JumpTarget$
    If TimeOfDay < 12 then JumpTarget$ = JumpTarget$ & "Morning"
    If (TimeOfDay > 12) and (TimeOfDay < 18) then JumpTarget$ = JumpTarget$ & "Afternoon"

rem Add StoryArcCode to JumpTarget$
    JumpTarget$ = JumpTarget$ & StoryArcCorde

rem Jump to next segment
End MainGameLoop

AliceBedroomMorning1:
rem First story arc for Alice in the bedroom in the morning.

End AliceBedroomMorning1

AliceBedroomAfternoon1:
rem First story arc for Alice in the bedroom in the afternoon.

End AliceBedroomAfternoon1
Forgive the awful pseudocode, I really do hope it makes sense! Thing is, I don't know if I can combine variables in Ren'Py like that to build a target that I want to jump to. Fundamentally, I believe I'm going to need a central single section of the game code that will act as a hub and a "calculate which bit to send them to next." I've simplified it a bit here, but because I use a standardized (for me) naming convention for everything, I should be able to predict what a code section will be called based on it's features.

I know there's a fudgey way to do it by basically creating an If case (So if JumpTarget$="AliceBedroomMorning1" then Goto AliceBedroomMorning1 and so on - but that could get huge and messy and calling straight from the variable name would be a lot tidier.

Can anyone offer me a suggestion as to wether I'm thinking the right way and I can do this in Ren'Py, or if I'm barking up the wrong tree? Thank you all!

I'll covert to actual code once the main parts have been Pseudocoded :D
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
The more common solution would be to jump to a common label, and then code something there which then jumps to another label based on the value of your variable(s).

Python:
    jump where_to_next

label where_to_next:

    if Room == "Bedroom":
        if TargetPerson == "Alice":
            if TimeOfDay < 12:
                If AliceArc == 2:
                    jump AliceBedroomMorning2
            elif TimeOfDay < 18:
                If AliceArc == 1:
                    jump AliceBedroomAfternoon1
            else:
                If AliceArc == 3:
                    jump AliceBedroomEvening3

        elif TargetPerson == "Betty":
            jump BettyBedroom

        else:
            jump EmptyBedroom

    elif Room == "Kitchen":
        # etc, etc.

But yes, if you don't want to code it like that, there is jump expression...

Python:
    jump where_to_next

label where_to_next:

    $ next_loc = TargetPerson + Room

    if TimeOfDay < 12:
        $ next_loc = next_loc + "Morning"
    elif TimeOfDay < 18:
        $ next_loc = next_loc + "Afternoon"
    else:
        $ next_loc = next_loc + "Evening"

    $ next_loc = next_loc + str(StoryArcCode)

    if not renpy.has_label(next_loc):
        $ next_loc = "Empty" + Room

    jump expression next_loc

Or something like that.

As an aside, I would suggest using lowercase for variables, labels and values of string variables you are checking.
It's all too easy to fuck up when using MixedCase and therefore is to use lowercase.
Obviously if you've already got a lot of code written, don't change it. But if you've only just started, better to adopt the standard naming conventions early.
 
Last edited:

SylvesterTemple

New Member
Sep 8, 2018
10
31
Thank god my pseudo code made sense to someone else - and thank you for the reply and information.

I'm still in the pseudocoding stage at the moment rather than writing anything in anger - however, I'm not sure I'll be able to make the concious move from camel casing - been using that for variables for the best part of 25 years (since the heady days of VB for DOS!) Overcoming that many years of being told one style and now being advised to switch to the opposite! lol

I'm glad to know that how I think it would work in my head is roughly how it'll work - jumping to expressions is going to be a better option for me, simply because I'm going to be building the jumptarget over a number of different parts of the label for ease of programming everything else.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
[...] using that for variables for the best part of 25 years (since the heady days of VB for DOS!) Overcoming that many years of being told one style and now being advised to switch to the opposite! lol

Luxury!!!

I harken back to UPPERCASE only languages on teletype terminals.

If is of course only a recommended convention. Its RenPy, practically anything will work.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,364
15,281
[...] however, I'm not sure I'll be able to make the concious move from camel casing - [...]
I'm permit to correct you, it's PascalCase, not camelCase.

This pure detail being said, I highly recommend you to switch to camelCase, and not only when using Ren'py, but whatever the language you use.

I know that naming conventions are strongly sticking habits, especially when you use them since so long. But we now are in a world where objects are everywhere. The difference between PascalCase and camelCase can seem small, since it's just the case of the first letter, but one of the two most spread conventions, whatever the language, is to name your object classes with an uppercase initial, whatever the convention used for the rest of the language.
[Side note for the readers curious to know, the second conventions is to use UPPERCASE_SNAKE for the name of constante.]

Therefore, by taking the habit to yourself drop the uppercase initial in your names, you'll identify more easily the "variables" (in the large meaning of the word) coming from the third party codes ; like here coming from Ren'py core.
 
  • Like
Reactions: 79flavors

SylvesterTemple

New Member
Sep 8, 2018
10
31
Actually, I was being lazy (trying to type just before I hit a meeting) - I normally prefix most things I can with a three letter code that is always in lowercase that gives me camelCase - Variables are var, Images are img, Sound is snd, Music is mus and so on.

So I will be using camelCase where I can, I just didn't include my usual prefixes before I pseudo coded it because it's instictive to prefix all items, so I rarely pseudo it!
 
  • Like
Reactions: 79flavors