Page 1 of 1

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

Posted: Wed May 04, 2022 11:37 am
by dicortesia
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!

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

Posted: Wed May 04, 2022 12:19 pm
by RicharDann
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

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

Posted: Wed May 04, 2022 2:57 pm
by dicortesia
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