A universal term to jump to previous label?

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
Treladon
Regular
Posts: 40
Joined: Sat Dec 31, 2016 3:20 pm
Projects: ToMaG, Feinted Game
Organization: Kuehler-Corrada Productions
Deviantart: Journie
Contact:

A universal term to jump to previous label?

#1 Post by Treladon »

Hi, guys.
So I have this imagebutton for the door on a specific building:

Code: Select all

    $ Llbuild2door = None #enter Jump("label blah")
    screen Llbuild2:
        imagebutton auto "Llbuild2_door_%s.png" focus_mask True action Llbuild2door hover_sound "dooropen short.wav"
But, during certain specified times, I want it to jump to a "restricted" label where the main character just says, "I can't go that way right now" that can be used for just about anything. But, after, I want it to just jump to the label it was at previously. Is there a term for a universal jump to the previous label?

Thanks for your help.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: A universal term to jump to previous label?

#2 Post by Ocelot »

You can call label instead of jumping to it.

Code: Select all

label something1:
    'some useless text'
    # Will save current location to call stack and jump to restricted label
    call restricted
    # will continue from there
    'something else'

label something2:
    'more text'
    call restricted
    'even more text'

label restricted:
    "I'm afraid I can't do that"
    # Will jum either to something1 or something2, depending where it was called from.
    return
< < insert Rick Cook quote here > >

User avatar
Treladon
Regular
Posts: 40
Joined: Sat Dec 31, 2016 3:20 pm
Projects: ToMaG, Feinted Game
Organization: Kuehler-Corrada Productions
Deviantart: Journie
Contact:

Re: A universal term to jump to previous label?

#3 Post by Treladon »

Oh, I didn't know call did that. But can I apply it to an imagebutton like so:

Code: Select all

    $ Lrbuild2door = None #enter Jump("label blah")
    screen Lrbuild2:
        imagebutton auto "Lrbuild2_door_%s.png" focus_mask True action Lrbuild2door hover_sound "dooropen short.wav" [\code]
I tried saying both:
[code] $Lrbuild2door = Call("restricted")[\code]
(thought it might act like jump) and
[code] $Lrbuild2door = call restricted [\code]
Both give an invalid syntax error.

User avatar
Enchant00
Regular
Posts: 136
Joined: Tue Jan 12, 2016 1:17 am
Contact:

Re: A universal term to jump to previous label?

#4 Post by Enchant00 »

- This is quite tricky :? The call will only work for screens and what your are doing is trying to assign it to a variable. Basically, its like trying to assign a function to a variable in which case you don't have to or rather you cant.Try this; I have yet to test this out but I'll get to it if you still have problems :lol:

Code: Select all

$ Lrbuild2door = False
screen Lrbuild2:
imagebutton auto "Lrbuild2_door_%s.png" focus_mask True action If('Lrbuild2door', true=Function(renpy.call, label="restricted")) hover_sound "dooropen short.wav" 
- So in theory, when you want it to jump to restricted then you have to first set the the variable $ Lrbuild2door to true then when they press the button it should call restricted label

Code: Select all

$ Lrbuild2door = True

Code: Select all

label restricted:
    "I'm afraid I can't do that"
    return # don't forget to put your return

User avatar
Winterslice
Veteran
Posts: 230
Joined: Mon Sep 28, 2015 3:51 am
Completed: The Next World, Golem Creation Kit
Organization: Illuminated Games
Contact:

Re: A universal term to jump to previous label?

#5 Post by Winterslice »

Another solution would be to store the label you want to return to in a variable as a string. Then, instead of jump, use jump expression like so:

Code: Select all

jump expression variable_containing_label_name
Then you could use SetVariable() and Jump() in the imagebutton, and return via the jump expression.

Example:

Code: Select all

$ return_destination = ""
$ current_label = "set_at_entering_a_label"
$ Lrbuild2door = [ SetVariable("return_destination", current_label), Jump("restricted") ]

imagebutton auto "Lrbuild2_door_%s.png" focus_mask True action Lrbuild2door hover_sound "dooropen short.wav" [\code]

label restricted:
    "I'm afraid I can't do that"
    jump expression return_destination

User avatar
Treladon
Regular
Posts: 40
Joined: Sat Dec 31, 2016 3:20 pm
Projects: ToMaG, Feinted Game
Organization: Kuehler-Corrada Productions
Deviantart: Journie
Contact:

Re: A universal term to jump to previous label?

#6 Post by Treladon »

Enchant00 wrote:- This is quite tricky :? The call will only work for screens and what your are doing is trying to assign it to a variable. Basically, its like trying to assign a function to a variable in which case you don't have to or rather you cant.Try this; I have yet to test this out but I'll get to it if you still have problems :lol:

Code: Select all

$ Lrbuild2door = False
screen Lrbuild2:
imagebutton auto "Lrbuild2_door_%s.png" focus_mask True action If('Lrbuild2door', true=Function(renpy.call, label="restricted")) hover_sound "dooropen short.wav" 
- So in theory, when you want it to jump to restricted then you have to first set the the variable $ Lrbuild2door to true then when they press the button it should call restricted label

Code: Select all

$ Lrbuild2door = True

Code: Select all

label restricted:
    "I'm afraid I can't do that"
    return # don't forget to put your return
Thanks Enchant00! It sort of worked. Since I still want to be able to input Jump("somelabel") for this door during certain times, what I did was:

Code: Select all

screen Lrbuild2:
    imagebutton auto "Lrbuild2_door_%s.png" focus_mask True action Lrbuild2door hover_sound "dooropen short.wav"

$ Llbuild2door = Function(renpy.call, label="restricted")

label restricted:
    a "I can't go that way right now."
    return 
It works, but at return, it restarts the game and goes to the start menu. Considering what I've read about call, this is not supposed to happen. Would you have any ideas?
WIP: The Tasks of Messengers and Guardians - Progress Page Here!

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: A universal term to jump to previous label?

#7 Post by gas »

Yes, it's quite indeed easy.
Have a list of rooms that store 0 for a location locked, 1 for an accessible room.
Another list contain the name of the labels of these rooms.
A third list contain possible exits for each room, like this:
exits=[(20,11,8),(11,3,40),...]
Where the first room could exit to room 20, 11, 8 . Remember that in python you count elements starting from 0, not 1.

Now create a label, called "roomnavigation" or similar.
When you enter a room, update the position (is the index of the list, so room=0, first room in the index, room 23= 22th room in the list).
Now a screen with conditional buttons, one for each exit of this room, that jump to proper label or, if locked, tell you can't.
After what you want to show there, jump back to the roomnavigation each time and that's all.

Yes, I can code this. No, not today, maybe in a couple of days.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: A universal term to jump to previous label?

#8 Post by gas »

1. create a new project (i used the legacy theme)
2. copy this and overwrite the script.rpy file
3. have fun.

Code: Select all

# You can place the script of your game in this file.

# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"

# Declare characters used by this game.
define e = Character('Eileen', color="#c8ffc8")


# The game starts here. With some default values. Declaring defaults of variables before the start label is kung fu.
default roomlocks=[0,0,1,1,0,1] #list how rooms are, from first to last, where: 0 is locked and 1 is unlocked. Note the square brackets. This is a LIST. With round brackets will be a tuple, an immutable type you cannot change later.
default position=0 #where 0 is the first room, 1 the second, 2 the third (is a python thing to count lists from 0, mandatory).
default oldposition=0 #this is a convenient variable to go back to the room if the next is closed. Keep faith.
default roomlabels=["kitchen","roof","garden","gym","crypt","bathroom"] #label of each room, in strict order.

#Well, not. The game starts here, instead.
label start:
    "Welcome to the domestic dungeon!"
    "If you add music, sound, images, a GUI, a plot, animations, screens, sprites..."
    "...pointers, icons, characters..."
    "...functions, debug, packaging, galleries..."
    "...and some love, you can release it to the underworld!"
    "Now explore this dungeon!"
    #start from a safe and unlocked location. In that given case, the garden.
    jump garden
label movemenu:
    ###########THIS IS THE ROUTINE THAT ALLOW MOVEMENT
    call screen movetheguy #at first, call a screen to decide direction
    $ direction=_return #the value returned by the screen is stored here. It's the number of the target room.
    $renpy.jump(roomlabels[direction]) #this nice thing jump to the correct label, as stored in roomlabels
label kitchen:
    ###########THE FORMULA FOR EACH ROOM IS:
    # update position
    # tell the position
    # call verifydoor function, that verify is the room is unlocked.
    # if unlocked, do whatever
    # then jump back to the movemenu routine

    $ position=0
    "You're now in the kitchen!"
    call verifydoor
    "It's a very nice kitchen. Anyway, nothing to eat."
    jump movemenu
label roof:
    $ position=1
    "You're up on the roof!"
    call verifydoor
    "You can see MY house from there!"
    "And if you reach that point in the game, you've seen everything."
    "It's time for a goodbye. Lemme know if you need something else!"
    "-coded in 17 minutes by Gas."
    $ renpy.full_restart() #<---USE THIS INSTEAD of a return statement to end the game, as you never know (believe me you NEVER know) if the return stack is void.
label garden:
    $ position=2
    "You reach the garden!"
    call verifydoor
    "I have a bad feeling about those carnivorous plants"
    jump movemenu
label gym:
    $ position=3
    "You're in the gym!"
    call verifydoor
    "HO HO ... Macho macho man! I gotta be a macho man!"
    #now an example of how unlock a locked room. Of course once.
    if roomlocks[0]==0: #if the target room is locked...
        "Hey, you found the key for the kitchen!"
        $ roomlocks[0]=1 #...now is unlocked
    jump movemenu
label crypt:
    $ position=4
    "You're down in the crypt!"
    call verifydoor
    "No, wait, it's not really a crypt, is more like a depot of old manga."
    if roomlocks[1]==0: #now we unlock the roof...
        "In the lower area of the house, you found the higher key, the roof one!"
        $ roomlocks[1]=1 #the roof is unlocked
    jump movemenu
label bathroom:
    $ position=5
    "You're in the bathroom!"
    call verifydoor
    "It's not a common bathroom. In fact those lasers are out of context."
    if roomlocks[4]==0:
        "A skeleton key hang from an hook. Are you sure this is a bathroom??"
        $ roomlocks[4]=1
    jump movemenu

label verifydoor:
    ###################### THIS LABEL CHECK IF THE ROOM IS LOCKED
    if roomlocks[position]==0: #if it's locked...
        "This room, however, is closed for some reason." #...sadness...
        $ position=oldposition #with this, go back to the previous room. No movement happen.
        jump movemenu #...and go back search elsewhere
    $ oldposition=position #update the old position, from that point on is where you're now. A little contrived, but is logic. And logic is not logical.
    return #if unlocked, continue with whatever else is narrated in that room

screen movetheguy():
    modal True #well, no need for that now, but is good practice
    $ yourroom=roomlabels[position] #where you're now
    text "You're in the [yourroom]" xalign 0.3 yalign 0.1 size 30
    vbox:
        xalign 0.5
        yalign 0.5
        text "Go to..."
        for i in range(len(roomlocks)): #for each damned room in this game...
            $daroom=roomlabels[i] #store the label name...
            if position != i: #of course, you skip the position you're are in now
                textbutton "[daroom]" action Return(i) #...and return the number of the room you want to go, from 0 to x.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Treladon
Regular
Posts: 40
Joined: Sat Dec 31, 2016 3:20 pm
Projects: ToMaG, Feinted Game
Organization: Kuehler-Corrada Productions
Deviantart: Journie
Contact:

Re: A universal term to jump to previous label?

#9 Post by Treladon »

gas wrote: Sat Jan 21, 2017 3:38 pm 1. create a new project (i used the legacy theme)
2. copy this and overwrite the script.rpy file
3. have fun.
Wow, this is fantastic! Thanks so much! This is definitely helpful. Sorry it took so long to respond - uni and everything. But I will spend some time with this.
WIP: The Tasks of Messengers and Guardians - Progress Page Here!

Post Reply

Who is online

Users browsing this forum: No registered users