Persistent variable not working (to unlock new 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
dicortesia
Newbie
Posts: 4
Joined: Wed May 04, 2022 10:08 am
Contact:

Persistent variable not working (to unlock new route) [SOLVED]

#1 Post by dicortesia » Wed May 04, 2022 11:37 am

Hello everyone,

I'm totally new to Renpy and know virtually nothing about coding... So far I've been relying on people asking questions and getting help on here;

I'm currently working on the last route in my silly VN and I tried following this tutorial as closely as possible: https://www.youtube.com/watch?v=43wJm3b ... lLearnings
The instructions are clear, and I feel like I followed them correctly, but it's not working. I am not using image buttons, so that might be why?

Here is what I did:

(This is all in the same .rpy file, specifically for the endings)

Code: Select all

label end1:

    $persistent.end1 = True
    
#I show a bunch of images here until return#
   
label end2:
	$persistent.end2 = True 

#I show a bunch of images here until return#	
	
label end3:
	$persistent.end3 = True
	
#I show a bunch of images here until return#
(This is in the "script.rpy" file)

Code: Select all

label start:

    init python:
        jump nroute_start
        sensitive persistent.end1 == True and persistent.end2 == True and persistent.end3 == True
      
     #Usual beginning of the game#   
I get this error message when I run the game:

```
File "game/script.rpy", line 7: invalid syntax
jump nroute_start
^
```

Also, this is my first post, so apologies if I did something wrong, feel free to correct me!

Thank you in advance!
Last edited by dicortesia on Fri May 06, 2022 4:53 am, edited 1 time in total.

User avatar
RicharDann
Veteran
Posts: 284
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Persistent variable not working (to unlock new route)

#2 Post by RicharDann » Wed May 04, 2022 12:19 pm

Can't check the video right now, but what exactly are you trying to do here? You're using various pieces of code that shouldn't be where you have them right now.

First is the init python block of code. This block is used to run pure python code, so it shouldn't be placed after label start, the code inside labels should usually be Ren'Py language statements. This is the cause of the error, you're giving this python a jump statement.

Also, the jump statement as you have it there would jump straight to nroute_start label, ignoring the next line. And about this line, sensitive is a button property, it shouldn't be inside a label, but in a button in a screen.

I guess you're trying to check if these 3 endings have been completed to unlock a new route at game start, for which you would need an "if" statement.

So, assuming I understand correctly, you'd need to do something like:

Code: Select all

label start:
    
    if persistent.end1 == True and persistent.end2 == True and persistent.end3 == True:
        
        jump nroute_start # This jump statement sends the player to the new ending route 
      
    # The rest of the game would run normally if the previous conditions weren't met
The most important step is always the next one.

User avatar
dicortesia
Newbie
Posts: 4
Joined: Wed May 04, 2022 10:08 am
Contact:

Re: Persistent variable not working (to unlock new route)

#3 Post by dicortesia » Wed May 04, 2022 2:57 pm

RicharDann wrote:
Wed May 04, 2022 12:19 pm
Can't check the video right now, but what exactly are you trying to do here? You're using various pieces of code that shouldn't be where you have them right now.

First is the init python block of code. This block is used to run pure python code, so it shouldn't be placed after label start, the code inside labels should usually be Ren'Py language statements. This is the cause of the error, you're giving this python a jump statement.

Also, the jump statement as you have it there would jump straight to nroute_start label, ignoring the next line. And about this line, sensitive is a button property, it shouldn't be inside a label, but in a button in a screen.

I guess you're trying to check if these 3 endings have been completed to unlock a new route at game start, for which you would need an "if" statement.

So, assuming I understand correctly, you'd need to do something like:

Code: Select all

label start:
    
    if persistent.end1 == True and persistent.end2 == True and persistent.end3 == True:
        
        jump nroute_start # This jump statement sends the player to the new ending route 
      
    # The rest of the game would run normally if the previous conditions weren't met
Ahh, thank you!

Yes, I was trying to unlock a new route after completing the others first, your solution worked!

Now I know code isn't as interchangeable as I thought, haha

Post Reply

Who is online

Users browsing this forum: Bing [Bot], GetOutOfMyLab