Returning to a previous line in Renpy

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
pandajenni
Newbie
Posts: 3
Joined: Wed Jan 27, 2016 11:50 am
Contact:

Returning to a previous line in Renpy

#1 Post by pandajenni » Wed Jan 27, 2016 11:56 am

I'm a renpy newbie and am in the process of creating a project using renpy. I managed to get the general programming to run, but I'm having a difficulty with return statements using the yes/no function. The line looks like this:


$layout.yesno_screen("Choose this music?", yes=NullAction(), no=Jump())

My goal is to get the no function to return to a previous line of coding for people to select another music choice. What would be the proper way to get the program to return to the previous line?

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: Returning to a previous line in Renpy

#2 Post by Iylae » Wed Jan 27, 2016 12:39 pm

Code: Select all

label returnPoint:
    # other stuff goes here
    $ layout.yesno_screen("Choose this music?", yes=Nullaction(), no=Jump("returnPoint"))
Not at a computer where I can test this, as my syntax may be wrong. Not sure if no=Jump("returnPoint") should be renpy.jump("returnPoint") instead.
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

User avatar
pandajenni
Newbie
Posts: 3
Joined: Wed Jan 27, 2016 11:50 am
Contact:

Re: Returning to a previous line in Renpy

#3 Post by pandajenni » Fri Jan 29, 2016 3:28 pm

Thank you for that code! The return function is definitely working, however the yes/no screen is no longer popping up--it's creating this infinite loop somehow. I'm including some of the code to see if it's something that can be simply fixed. I really appreciate all of the help!

Code: Select all

scene Driving
"You are driving through a city with a lot of traffic (both cars and pedestrians). It is also raining very heavily outside. You want to make sure that you maintain focus on driving safely through this environment. You need to focus and pay careful attention to the road and traffic."
label returnPoint:
label MusicSelect:
"Please choose the music you would like to hear."
menu:
    
    "GOAL: How would you keep your focus while driving?"
    with dissolve
    "[hap1]":
        $layout.yesno_screen ("Choose this music?", yes=NullAction(), no=renpy.jump("returnPoint"))
        jump choice_hap1
There are four other options of music as well, which is why I placed the return point at that location. Again, thanks for any input!

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: Returning to a previous line in Renpy

#4 Post by Iylae » Sat Jan 30, 2016 12:15 pm

Its creating a loop because you're not altering anything after returning to the returnPoint.

If you have a list of music I suggest cycling through the index and increasing it by 1 each time the loop is performed e.g.

Code: Select all

label MusicSelect:
    $ musicList = [musicA, musicB, etc]  #  make a list of music
    $ index = -1  #  (as index is incremented at the start of the loop, it needs to start at -1
label returnPoint:
python:   # saves typing $ each line
    index += 1  #  increments the index
    if index > len(musicList):   #  if the index would go past the end of the music list
        index = 0    #  start again at the beginning of the list
    "Please choose the music you would like to hear."
    menu:
    
        "GOAL: How would you keep your focus while driving?"
        with dissolve
        "[musicList[index]]":  #  gets the music at the index 
        $layout.yesno_screen ("Choose this music?", yes=renpy.jump("choice_hap"), no=renpy.jump("returnPoint"))

label choice_hap:
    "You have chosen music [musicList[index]]"  #  how to find which music was actually chosen.
There are probably better ways of doing this but this is how I'd do it. I haven't tested the code above (as usual), but I hope you understand the concept.
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]