Adding persistent code for an unlockable route [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.
Post Reply
Message
Author
User avatar
heartfragment
Regular
Posts: 109
Joined: Tue Nov 10, 2015 12:10 am
Projects: Heart Fragment
Tumblr: heartfragment
itch: heartfragment
Contact:

Adding persistent code for an unlockable route [SOLVED]

#1 Post by heartfragment »

Hello everyone, I hope this isn't too stupid of a question this time.
In my game I want for one route to be unlockable after every other route in the game has been played.

I have added to each of the original routes (not unlockable) something like the following:

Code: Select all

label kei:
    "This is where Kei's route begins. Look forward to it in the full version of the game!"
        
        return
        
    else:
        $ persistent.kei_complete = True
        $ persistent.inigo_unlock += 1
    
        return
This seemed to be working fine, until I updated Renpy to the newest version. Now when I get to that point in the game while testing it, I get the following error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 1249, in script
    $ persistent.inigo_unlock += 1
  File "game/script.rpy", line 1249, in <module>
    $ persistent.inigo_unlock += 1
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'int'

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

Full traceback:
  File "game/script.rpy", line 1249, in script
    $ persistent.inigo_unlock += 1
  File "C:\Users\taure\Documents\Renpy\renpy\ast.py", line 814, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\taure\Documents\Renpy\renpy\python.py", line 1719, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 1249, in <module>
    $ persistent.inigo_unlock += 1
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'int'

Windows-8-6.2.9200
Ren'Py 6.99.12.4.2187
Heart Fragment DEMO
I'm a bit unsure what this means and how to fix it. If anyone can help me out I'd really appreciate it, thanks!
Last edited by heartfragment on Tue May 02, 2017 4:25 am, edited 1 time in total.
Published Project:
Image

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Adding persistent code for an unlockable route

#2 Post by xela »

Try something along these lines:

Code: Select all

if persistent.inigo_unlock is None:
    $ persistent.inigo_unlock = 0
$ persistent.inigo_unlock += 1
Like what we're doing? Support us at:
Image

User avatar
heartfragment
Regular
Posts: 109
Joined: Tue Nov 10, 2015 12:10 am
Projects: Heart Fragment
Tumblr: heartfragment
itch: heartfragment
Contact:

Re: Adding persistent code for an unlockable route

#3 Post by heartfragment »

Hi xela, thanks for the help!
I tried this out but now when I go through each route and attempt to open to Inigo's at the end, it still shows up as locked. Did I do something wrong?

Sorry, this is probably a really amateur mistake.^^;
Published Project:
Image

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Adding persistent code for an unlockable route

#4 Post by xela »

No clue, it should fix the error and function as counter. It's impossible to say what else may be going wrong as:

Code: Select all

label kei:
    "This is where Kei's route begins. Look forward to it in the full version of the game!"
       
        return
       
    else:
        $ persistent.kei_complete = True
        $ persistent.inigo_unlock += 1
   
        return
is incomplete and will not run (else without an if).
Like what we're doing? Support us at:
Image

User avatar
heartfragment
Regular
Posts: 109
Joined: Tue Nov 10, 2015 12:10 am
Projects: Heart Fragment
Tumblr: heartfragment
itch: heartfragment
Contact:

Re: Adding persistent code for an unlockable route

#5 Post by heartfragment »

I'm trying to understand the code and it seems as though its resetting the counter to zero each time the code goes through. I need it to count up to 4 to unlock Inigo's route, after all 4 other routes have been complete. Am I understanding it correctly? Is there any way to do this?
Published Project:
Image

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Adding persistent code for an unlockable route

#6 Post by Imperf3kt »

The simplest way is to add a persistent variable to say if the route is seen in full THEN add a persistent variable that adds+1 IF that route has been seen, finally however a user selects the route would have IF persistent.value = 4:

Something like this:

Code: Select all

default persistent.routes_seen = 0
default persistent.route_01 = False
default persistent.route_02 = False
default persistent.route_03 = False
default persistent.route_04 = False

label start:
    "Muh text"
    if not persistent.route_01:
        $ persistent.route_01 = True
        $ persistent.routes_seen += 1
    return
# repeat until route 4
Then, elsewhere:

Code: Select all

if persistent.routes_seen = 4:
    jump super_secret_route_05
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
heartfragment
Regular
Posts: 109
Joined: Tue Nov 10, 2015 12:10 am
Projects: Heart Fragment
Tumblr: heartfragment
itch: heartfragment
Contact:

Re: Adding persistent code for an unlockable route

#7 Post by heartfragment »

Hi Imperf3kt, thanks for the help. One question! When I try to load Inigo, the secret route, I get this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 1354, in script
    if persistent.routes_seen = 4:
SyntaxError: invalid syntax (game/script.rpy, line 1354)

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

Full traceback:
  File "game/script.rpy", line 1354, in script
    if persistent.routes_seen = 4:
  File "C:\Users\taure\Documents\Renpy\renpy\ast.py", line 1656, in execute
    if renpy.python.py_eval(condition):
  File "C:\Users\taure\Documents\Renpy\renpy\python.py", line 1748, in py_eval
    code = py_compile(code, 'eval')
  File "C:\Users\taure\Documents\Renpy\renpy\python.py", line 584, in py_compile
    raise e
SyntaxError: invalid syntax (game/script.rpy, line 1354)

Windows-8-6.2.9200
Ren'Py 6.99.12.4.2187
Heart Fragment DEMO
This is what the code looks like.

Code: Select all

    menu:
        "Kei":
            jump kei
        "Clive":
            jump clive
        "Shannon":
            jump shannon
        "Jasper":
            jump jasper
        "Inigo":
            if persistent.routes_seen = 4:
                jump inigo
            else:
                "This route can only be unlocked by achieving all other good endings."
                "Good luck. You'll get there soon!"
                menu:
                    "Kei":
                        jump kei
                    "Clive":
                        jump clive
                    "Shannon":
                        jump shannon
                    "Jasper":
                        jump jasper
        
label kei:
    if not persistent.route_01:
        $ persistent.route_01 = True
        $ persistent.routes_seen += 1
    "This is where Kei's route begins. Look forward to it in the full version of the game!"
        
    return

    else:
        return
    
label clive:
    if not persistent.route_02:
        $ persistent.route_02 = True
        $ persistent.routes_seen += 1
    "This is where Clive's route begins. Look forward to it in the full version of the game!"
        
    return
    
    else:
        return
    
label shannon:
    if not persistent.route_03:
        $ persistent.route_03 = True
        $ persistent.routes_seen += 1
    "This is where Shannon's route begins. Look forward to it in the full version of the game!"
        
    return
        
    else:
        return
    
label jasper:
    if not persistent.route_04:
        $ persistent.route_04 = True
        $ persistent.routes_seen += 1
    "This is where Jasper's route begins. Look forward to it in the full version of the game!"
        
    return
    
else:
        return
    
label inigo:
    "This is where Inigo's route begins. Look forward to it in the full version of the game!"
    
    return
I have a feeling I'm probably missing something very simple... I'm sorry for being such a bother here.

Edit: I thought I had arranged the else and ifs in the wrong order so I changed things up a bit to see if that would fix it, and now get this error when launching the game.

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 1391: expected statement.
    else:
        ^

File "game/script.rpy", line 1432: expected statement.
    else:
        ^

File "game/script.rpy", line 1473: expected statement.
    else:
        ^

File "game/script.rpy", line 1514: expected statement.
    else:
        ^

Ren'Py Version: Ren'Py 6.99.12.4.2187
Published Project:
Image

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

Re: Adding persistent code for an unlockable route

#8 Post by philat »

First, I don't see why you have routes_seen when you have bools for the route_01, route_02, etc. There doesn't seem to be much point. By using the increment, you get a second line of code that is unnecessary -- the if not persistent.route_01 part, which could be omitted altogether if you only set persistent.route_01 (for example) to True.

Second, you're setting these at the beginning of the route rather than at the end -- unless this is just for testing purposes, this seems like a bad idea.

Third, your actual error is from using persistent.routes_seen = 4 instead of persistent.routes_seen == 4, but as I noted, there's no reason to use the integer value really.

Code: Select all

    menu:
        "Kei":
            jump kei
        "Clive":
            jump clive
        "Shannon":
            jump shannon
        "Jasper":
            jump jasper
        "Inigo":
            if persistent.route_01 and persistent.route_02 and persistent.route_03 and persistent.route_04: # use instead of persistent.routes_seen
                jump inigo
            else:
                "This route can only be unlocked by achieving all other good endings."
                "Good luck. You'll get there soon!"
                menu:
                    "Kei":
                        jump kei
                    "Clive":
                        jump clive
                    "Shannon":
                        jump shannon
                    "Jasper":
                        jump jasper
        
label kei:
    #if not persistent.route_01:
        #$ persistent.route_01 = True
        #$ persistent.routes_seen += 1
    $ persistent.route_01 = True # the above three lines can be exchanged for one line.
    "This is where Kei's route begins. Look forward to it in the full version of the game!"
        
    return

    else:
        return
    

User avatar
heartfragment
Regular
Posts: 109
Joined: Tue Nov 10, 2015 12:10 am
Projects: Heart Fragment
Tumblr: heartfragment
itch: heartfragment
Contact:

Re: Adding persistent code for an unlockable route

#9 Post by heartfragment »

Ahh thank you for explaining philat! I completely understand now. Sorry for my silly mistakes. I appreciate your help!! Everything is working perfectly now!
Published Project:
Image

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Adding persistent code for an unlockable route [SOLVED]

#10 Post by Imperf3kt »

I didn't know you could use "and"
Thanks for the heads up, that should help neaten a few things.
philat wrote: your actual error is from using persistent.routes_seen = 4 instead of persistent.routes_seen == 4, but as I noted, there's no reason to use the integer value really.
That was my error, my phone's auto-correct deleted one of the = in my post and I didn't notice.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Toma