Return won't end game, causes crash or loop [SOLVED]

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
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Return won't end game, causes crash or loop

#16 Post by ISAWHIM »

Use this, instead of trying to "hope" that the "Return without a Call" actually works in-line within blocks...

Code: Select all

label something:
    "Yay, we started"
    "Goodbye!"
    # Jump to the end_game to force it to end, from any location, block or function
    # or python... $ renpy.jump("end_game")
    jump end_game

label otherstuff:
    "Invisible doughnuts! Mmmmm"

# Place this at the actual END of the file...
label end_game:
    # This ends the game. You should JUMP here, not CALL.
    "THE END"
    return

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: Return won't end game, causes crash or loop

#17 Post by trooper6 »

Philat beat me to it! That is the sort of thing I was thinking about doing. One screen! Two variables--one for picked, one for left! Jumping to a label after returning from the screen based on who is left.

All good!
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
illuminate001
Veteran
Posts: 412
Joined: Thu Jul 02, 2009 1:46 pm
Completed: DSGR, Let's MEAT Adam, Sexy Litter, Bara Boarders
Projects: Secret Project
Organization: Soulsoft Electronic Arts
Tumblr: soulsoftea
itch: soulsoftea
Location: Orlando, FL
Contact:

Re: Return won't end game, causes crash or loop

#18 Post by illuminate001 »

First off, I wanna say thank you Trooper6, Philat, ISAWHIM :wink:, actually all you guys, for really rallying around and trying to help and advise me through this problem! I just woke up and so I'm terribly groggy and unable to process code in my brain right now lol...

However I'm planning on reading the script revision you (Philat) did and analyzing the differences and what makes it more efficient and really trying to understand it. Especially if it works and fixes the problem! ^_^

I'll probably start attempting to work in the suggestions into my code today. I'll keep you all posted! However please if anyone else has any fixes keep posting em! The more the merrier I say! (so far all the feedback has been pretty consolidated in how this should be fixed so it's not confusing/getting conflicting advice)
ImageImage
ImageImage

User avatar
illuminate001
Veteran
Posts: 412
Joined: Thu Jul 02, 2009 1:46 pm
Completed: DSGR, Let's MEAT Adam, Sexy Litter, Bara Boarders
Projects: Secret Project
Organization: Soulsoft Electronic Arts
Tumblr: soulsoftea
itch: soulsoftea
Location: Orlando, FL
Contact:

Re: Return won't end game, causes crash or loop

#19 Post by illuminate001 »

UPDATE: Once I put in the new reformatted screen structure provided by philat, on top of cleaning up labels, the game no longer loops upon hitting Return! Yay!

There's some fallout when I made sure no labels were indented but it's alot better now at least. The previous code was a mess of labels within labels and an indentation NIGHTMARE. I'm unsure how the game was able to appear stable for so long. lol.

Also to ensure the Return worked I used a suggestion from my friend Arowana and am using $renpy.full_restart() instead of a typical return just in case. It seems to work well. I've provided philats code below because I now have 2 more questions related to fallout from implementation of philat's code that I could use help with. I'll make another post below. Thank you all so much!
philat wrote:

Code: Select all

default picked = None # instead of picked_bart, picked_lucky, etc., I have one picked and one left variable.
default left = None

screen pick_partner():

    hbox: # this is where you pick who to take
        ypos 370
        # seems easier to determine xpos through spacing and align (I mean, you don't have to, it's just simpler)
        
        imagebutton:
            idle "gui/main_bart_idle.png"
            hover "gui/main_bart_hover.png"
            selected_idle "gui/main_bart_hover.png" 
            insensitive im.Grayscale("gui/main_bart_idle.png") 
            # selected_idle and insensitive are documented in the imagebutton documentation and will make your life easier
            action [ SensitiveIf(picked==None), SetVariable("picked", "bart") ] # SensitiveIf is also documented under screen actions if you want to learn more

        imagebutton:
            idle "gui/main_lucky_idle.png"
            hover "gui/main_lucky_hover.png"
            selected_idle "gui/main_lucky_hover.png"
            insensitive im.Grayscale("gui/main_lucky_idle.png") 
            action [ SensitiveIf(picked==None), SetVariable("picked", "lucky") ]

        imagebutton:
            idle "gui/main_pierce_idle.png"
            hover "gui/main_pierce_hover.png"
            selected_idle "gui/main_pierce_hover.png"
            insensitive im.Grayscale("gui/main_pierce_idle.png") 
            action [ SensitiveIf(picked==None), SetVariable("picked", "pierce") ]

    if picked: # once picked has a value other than None, the hbox below will show up so you can choose who to leave. Until then, it's hidden.
        hbox:
            ypos 680
            # same as above -- I put it in an hbox because I don't want to deal with xpos numbers, but feel free to change

            imagebutton:
                idle "gui/main_bart_idle.png"
                hover "gui/main_bart_hover.png"
                selected_idle "gui/main_bart_hover.png"
                insensitive im.Grayscale("gui/main_bart_idle.png") 
                action [ SensitiveIf(picked!="bart"), SetVariable("left", "bart"), Return() ] 
                # is sensitive only if picked is not "bart" -- i.e., you can't choose to both take and leave bart. 
                # Also returns from the called screen -- you can also do this with Show and Hide and modal if you'd prefer.

            imagebutton:
                idle "gui/main_lucky_idle.png"
                hover "gui/main_lucky_hover.png"
                selected_idle "gui/main_lucky_hover.png"
                insensitive im.Grayscale("gui/main_lucky_idle.png") 
                action [ SensitiveIf(picked!="lucky"), SetVariable("left", "lucky"), Return() ]

            imagebutton:
                idle "gui/main_pierce_idle.png"
                hover "gui/main_pierce_hover.png"
                selected_idle "gui/main_pierce_hover.png"
                insensitive im.Grayscale("gui/main_pierce_idle.png") 
                action [ SensitiveIf(picked!="pierce"), SetVariable("left", "pierce"), Return() ]

label picky:
    scene bg pickpartner
    with dissolve

    call screen pick_partner()

    jump expression left + "_left" # jumps to bart_left / lucky_left / pierce_left depending on the value of the variable left

    # return <- this return does nothing and I'm not sure why it's there. Once you jump to the next label, you shouldn't be coming back here at all
ImageImage
ImageImage

User avatar
illuminate001
Veteran
Posts: 412
Joined: Thu Jul 02, 2009 1:46 pm
Completed: DSGR, Let's MEAT Adam, Sexy Litter, Bara Boarders
Projects: Secret Project
Organization: Soulsoft Electronic Arts
Tumblr: soulsoftea
itch: soulsoftea
Location: Orlando, FL
Contact:

Re: Return won't end game, causes crash or loop

#20 Post by illuminate001 »

So here are 2 problems that are direct fallout from philat's code:

1. My previous if picked_pierce:, if picked_lucky:,etc. statements no longer work. I'm guessing I need to change them to something like if picked == pierce: ???

2. BUG: If I create a save just before initiating the code that philat provided, then load that save I get an error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 7056, in script
    call screen pick_partner()
  File "renpy/common/000statements.rpy", line 471, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "game/script.rpy", line 598, in execute
    screen pick_partner():
  File "game/script.rpy", line 598, in execute
    screen pick_partner():
  File "game/script.rpy", line 600, in execute
    hbox: # this is where you pick who to take
  File "game/script.rpy", line 604, in execute
    imagebutton:
  File "game/script.rpy", line 604, in keywords
    imagebutton:
NameError: name 'picked' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 7056, in script
    call screen pick_partner()
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\ast.py", line 1706, in execute
    self.call("execute")
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\ast.py", line 1724, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\statements.py", line 145, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 471, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\exports.py", line 2521, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\ui.py", line 285, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\display\core.py", line 2504, in interact
    scene_lists.replace_transient()
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\display\core.py", line 809, in replace_transient
    self.remove(layer, tag)
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\display\core.py", line 1094, in remove
    self.hide_or_replace(layer, remove_index, "hide")
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\display\core.py", line 1018, in hide_or_replace
    d = oldsle.displayable._hide(now - st, now - at, prefix)
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\display\screen.py", line 443, in _hide
    self.update()
  File "C:\Users\John John\Desktop\John\Games\renpy\renpy\display\screen.py", line 578, in update
    self.screen.function(**self.scope)
  File "game/script.rpy", line 598, in execute
    screen pick_partner():
  File "game/script.rpy", line 598, in execute
    screen pick_partner():
  File "game/script.rpy", line 600, in execute
    hbox: # this is where you pick who to take
  File "game/script.rpy", line 604, in execute
    imagebutton:
  File "game/script.rpy", line 604, in keywords
    imagebutton:
  File "<screen language>", line 610, in <module>
NameError: name 'picked' is not defined

Windows-8-6.2.9200
Ren'Py 6.99.12.2.2029
LetsMeatAdam 0.0
Does anyone know why this might be or what this means?
ImageImage
ImageImage

philat
Eileen-Class Veteran
Posts: 1910
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Return won't end game, causes crash or loop

#21 Post by philat »

1. Yes. if picked == "pierce": to be exact.

2. This shouldn't be happening, as long as you have the default picked = None line somewhere. In theory, this should allow you to use old saves from before the picked variable existed. That said, since you've apparently changed a lot of the script, old saves may not be compatible. If you run it through from the beginning, there really shouldn't be an issue.

User avatar
sunwave
Regular
Posts: 45
Joined: Fri Apr 15, 2016 2:26 pm
Location: Netherlands
Contact:

Re: Return won't end game, causes crash or loop

#22 Post by sunwave »

EDIT: Well, Philat already answered, so this post is mostly non-relevant. But hey, I typed it out already so here you are. XD Plus I always explain every step, even if they seem obvious, just for other users that might also take a look at it. So that's why I included the explanations for the button codes. Sorry about that. =P /EDIT

Hello. I'm *really* not that good at coding. You seem better at it than me, to be honest. But I can understand it quite well nonetheless, so I can at least provide a quick answer for your question #1 (in case you have time to work on it before one of the others can comment).

Your assumption is correct. With the code from Philat the variables picked_pierce, picked_lucky and picked_bart are combined into the single variable picked. So instead of 3 variables you're only using one. He sets this variable in this section (this one is the button for picking "bart"):

Code: Select all

        imagebutton:
            (snip)
            action [ SensitiveIf(picked==None), SetVariable("picked", "bart") ]
The same for the left variables that he combined into one variable with 4 different values (if you include the default "None"). He sets this in the next set of buttons (this one is for leaving "pierce"):

Code: Select all

            imagebutton:
                (snip)
                action [ SensitiveIf(picked!="pierce"), SetVariable("left", "pierce"), Return() ]
Note that the button checks if the variable picked!="pierce", so you can't leave pierce if you picked pierce (obviously). This makes the code a lot more refined (if not easier) since each button checks the same variable, in the same manner, just for another value. Then, the script uses the single variable left = "????" to just go to one of three labels, without having to check for each variable of picked_pierce, picked_lucky and picked_bart:

Code: Select all

jump expression left + "_left"
It's pretty smart actually (or maybe pretty natural if you're good at coding?). I would totally have done the same thing as you did with all the different variables. The code for my own VN is not very refined. XD

NOTE: Don't forget to set a default value. Perhaps that's the problem with your error. I'm not sure. Also, you should use the exact strings that philat mentioned, including quotes, because you're using strings as variables. So:

Code: Select all

picked = "pierce" #to set the variable
if picked == "pierce": #to use/check the variable

User avatar
illuminate001
Veteran
Posts: 412
Joined: Thu Jul 02, 2009 1:46 pm
Completed: DSGR, Let's MEAT Adam, Sexy Litter, Bara Boarders
Projects: Secret Project
Organization: Soulsoft Electronic Arts
Tumblr: soulsoftea
itch: soulsoftea
Location: Orlando, FL
Contact:

Re: Return won't end game, causes crash or loop

#23 Post by illuminate001 »

@Philat
philat wrote:1. Yes. if picked == "pierce": to be exact.

2. This shouldn't be happening, as long as you have the default picked = None line somewhere. In theory, this should allow you to use old saves from before the picked variable existed. That said, since you've apparently changed a lot of the script, old saves may not be compatible. If you run it through from the beginning, there really shouldn't be an issue.
1. Yes it works perfectly thank you!

2. I am actually playing my game from the beginning again anyways to do more bug testing cause of all the reformatting. I'll let you know if that is the case. default picked = None is definitely defined at the start of the script where all the other variables are defined.

Anyways Philat thank you so much~! You've been an especially great help. :P

@Sunwave - No problem! :D Please explain as it may be a help to others like you said. I do get it now once i sat down and really looked at what the code is doing. I think having a coders mind is definitely something that is not part of my brain atm so I'm still learning how to do things efficiently and less with spit and tape. lol
ImageImage
ImageImage

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], Yone28