[SOLVED] Complicated Points-Based Endings... (cont.)

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
Sanae
Regular
Posts: 37
Joined: Sat Jul 28, 2012 4:26 pm
Contact:

[SOLVED] Complicated Points-Based Endings... (cont.)

#1 Post by Sanae » Sat Jul 28, 2012 4:58 pm

... With Numerous Factors

Hi! Okay, I'm making a VN with an ending system similar to Princess Maker. Basically, certain amount of points with give you certain endings. If you want an example of how those endings work, click here. Now the tutorial for the Points Based system has been very helpful, but the problem is - I'm not sure how to write the codes for the complicated endings.

Let's just use a random example:

Say for example, we have these initial stats in the start:

Code: Select all

    $ social_reputation = 0
    $ refinement = 0
    $ charisma = 0
    $ fighting_reputation = 0
    $ sin = 0
Now, if anyone has played PM, they know that there are job-based endings with some priority, as well as others based on sin. In my case, I have 14 endings, so with these points, there are various ways to approach it.

For example, say we want a Queen Ending. Our Queen would need very high refinement and high stats in the other departments, but low sin. (In my game, if the sin reaches 50, it's an automatic cross to the dark side endings.) I've tried to write something like this at first:

Code: Select all

   if refinement >= 80
   and 70 < social_reputation >= 50 
   and 80 < charisma >= 60
   and 70 < fighting_reputation >= 50
   and sin < 50:
       jump queenend
Note that it must INCLUDE the other factors, not necessarily an if/or case. For example, another ending (the Concubine) would have this:

Code: Select all

   elif charisma >= 80
   and 70 < social_reputation >= 50
   and sin < 50:
       jump concubineend
But that gave me errors like this:

Code: Select all

File "game/endings.rpy", line 4: reached end of line when expecting ':'.
    if refinement  >= 80 and 70 < social_reputation >= 50 and 80 < charsima >= 60
ad nauseum with each part.

Then I've tried to switch it around like so this random example:

Code: Select all

   if refinement  >= 80:
      and if 70 < social_reputation >= 50: 
             and if charisma > 30:
And still an error like this:

Code: Select all

File "game/endings.rpy", line 10: expected statement.
    if refinement >= 80 
again, ad nausem

I scratched through the boards and tutorials and such, but I don't think I've run into any solution for this case. May you please assist me on how I should construct it? Unless this is impossible with Ren'Py.

Thanks in advance!
Last edited by Sanae on Sun Jul 29, 2012 1:36 pm, edited 3 times in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Complicated Points-Based Endings With Numerous Factors

#2 Post by Alex » Sat Jul 28, 2012 5:44 pm

Just put all these parameters in one line that ends with ":"

Code: Select all

    if refinement >= 80 and 70 < social_reputation >= 50 and 80 < charisma >= 60 and 70 < fighting_reputation >= 50 and sin < 50:
        jump queenend

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Complicated Points-Based Endings With Numerous Factors

#3 Post by Levrex » Sun Jul 29, 2012 1:15 am

Or just don't use "and", because that's a bad syntax.
And it'll look like this.

Code: Select all

if refinement  >= 80:
      if 70 < social_reputation >= 50: 
             if charisma:
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

Sanae
Regular
Posts: 37
Joined: Sat Jul 28, 2012 4:26 pm
Contact:

Re: Complicated Points-Based Endings With Numerous Factors

#4 Post by Sanae » Sun Jul 29, 2012 6:41 am

Levrex wrote:Or just don't use "and", because that's a bad syntax.
And it'll look like this.

Code: Select all

if refinement  >= 80:
      if 70 < social_reputation >= 50: 
             if charisma:
Out of curiosity, how would this work with an elif statement? Would it be like this?

Code: Select all

elif refinement >= 80:
      elif 70 < social_reputation >= 50: 
             elif charisma: 
Or do I define the first variable as elif, and the rest as "if"s? And thank you both Levrex and Alex! But yeah, I'm getting a "invalid syntax" error with your approach, Alex.

EDIT: Nevermind, I just tested it, and it works if you vary the elif with the ifs! Now I have a new problem instead:

To test the endings, I gave these random variables:

Code: Select all

    $ social_reputation = 15
    $ refinement = 25
    $ charisma = 100
    $ fighting_reputation = 20
    $ sin = 60

    $ seth_love = False
Not enough for Queen, right? But somehow I got the Queen ending! Clearly my greater than or equal to variables are messed up, I supposed?

This is a snippet for what I wrote:

Code: Select all

label endings:
   
#BEST ENDING
   if refinement  >= 80:
       if 70 < social_reputation >= 50:
           if 80 < charisma >= 60:
               if 70 < fighting_reputation >= 50:
                   if sin < 50:
                       jump queenend       
   
#GOOD ENDINGS       
   elif 80 < refinement >= 50: 
       if 70 < social_reputation >= 50:
           if 80 < charisma >=60:
               if 70 < fighting reputation >=50:
                   if sin < 50:
                       jump pcend
       
   elif charisma >= 80: 
       if 70 < social_reputation >= 50: 
           if sin < 50: 
               jump concubineend
       
   elif fighting_reputation >= 70: 
       if 70 < social_reputation >= 50: 
           if sin < 50:
               jump knightend
       
   elif social_reputation >= 70:
       if sin < 50:
           jump plend  
         
#NEUTRAL ENDINGS
   elif charisma >= 60: 
       if 30 < refinement < 60: 
           if sin < 50:
               if seth_love == False:
                   jump nobleloverend
        
   elif 30 < charisma < 60: 
       if refinement < 30: 
           if sin < 50: 
               if seth_love == False:
                   jump randomloverend    
        
   elif 40 < refinement < 60: 
       if charisma < 60: 
           if sin < 50: 
               if seth_love == False:
                   jump lnend
        
   elif 40 < refinement < 60: 
       if charisma < 60: 
           if sin < 50: 
               if seth_love == True: 
                   jump rlend     

#BAD ENDINGS
   elif refinement >= 70: 
       if sin >= 50:
           jump overlordend
      
   elif 70 < charisma >= 50: 
       if sin >= 50:
           jump prostituteend
       
   elif charisma >= 70: 
       if sin >= 50:
           jump slaveend
       
   elif fighting_reputation >= 70: 
       if sin >= 50:
           jump bkend
    
#WORST ENDING
   else:
        jump destituteend



And the labels look like this:

Code: Select all

label queenend:
    scene cgqueen
    n "Leliana is queen woot!"
    if seth_love == True:
        "and seth is her king!"
    else: 
        "Leliana was eventually married to some dude"
    jump credits
    
label pcend:
    scene cgprincessconsort
    n "leliana is the princess consort woot!"
    if seth_love == True:
        "sorry seth :("
    else: 
        "and now the credits!"
    jump credits

label prostituteend:
    scene cgprostitute
    n "lelianna is working off the streets onos"
    if seth_love == True:
        "ouch seth"    
    else: 
        "and now the credits!"
    jump credits 

etc.

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Complicated Points-Based Endings... (cont.)

#5 Post by apricotorange » Sun Jul 29, 2012 7:53 am

Are you sure the variables are actually set to what you think they are? (Make sure you aren't loading from a save.)

On a side note, "80 < charisma >= 60" looks like a typo; are you sure you didn't mean "80 > charisma >= 60" or something like that?

Sanae
Regular
Posts: 37
Joined: Sat Jul 28, 2012 4:26 pm
Contact:

Re: Complicated Points-Based Endings... (cont.)

#6 Post by Sanae » Sun Jul 29, 2012 8:59 am

apricotorange wrote:Are you sure the variables are actually set to what you think they are? (Make sure you aren't loading from a save.)

On a side note, "80 < charisma >= 60" looks like a typo; are you sure you didn't mean "80 > charisma >= 60" or something like that?
Thank you for pointing out the typo! D'oh me! I went around and changed all the "less than" signs that were contradictory.

Unfortunately, it didn't seem to fix my problem. And I'm not loading from a save: As soon as the game began, as well as the variables were named, I "jumped" to the endings portion just to try them out, so it's a completely new game. Unless maybe I should delete the persistent data or something?

User avatar
Ziassan
Veteran
Posts: 231
Joined: Thu Jun 09, 2011 8:14 pm
Contact:

Re: Complicated Points-Based Endings... (cont.)

#7 Post by Ziassan » Sun Jul 29, 2012 9:06 am

Think to correct all the things you did like that

Code: Select all

if 70 < social_reputation >= 50:
           if 80 < charisma >= 60:
               if 70 < fighting_reputation >= 50:
actually your script test if social_reputation is greater than 70, if charisma is greater than 80, etc etc.

Also for you bug, your "if" statements can't be broken, that means something is going wrong in the values, you should try to output them in your text too see if they're changing by themself for some reasons.

Another explication could be that the typo errors you made like I pointed above make Ren'py avoid the test and avoid all the possible jump, if your queen ending text is after these tests, it could be the reason.
Image
I like to create things. Mostly on the music side.
http://soundcloud.com/ziassan

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Complicated Points-Based Endings... (cont.)

#8 Post by Levrex » Sun Jul 29, 2012 9:16 am

Nothing is wrong with the values, it is just an improper "elif" use (of course, "<"-s too, but she (Sanae is a good girl, am i right?) corrected them).
By the way, Ziassan, there is some good music you have there. A Higurashi Kai feel to them for me. Maybe just a perception.

===

Just to remind, use "elif" ONLY with the same value which the corresponding "if" uses. Corresponding means the same indentation.
When i corrected your code, Sanae, it got me a "slaveend". I wonder, what would it look like...
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

Sanae
Regular
Posts: 37
Joined: Sat Jul 28, 2012 4:26 pm
Contact:

Re: Complicated Points-Based Endings... (cont.)

#9 Post by Sanae » Sun Jul 29, 2012 10:13 am

Levrex wrote:Nothing is wrong with the values, it is just an improper "elif" use (of course, "<"-s too, but she (Sanae is a good girl, am i right?) corrected them).
By the way, Ziassan, there is some good music you have there. A Higurashi Kai feel to them for me. Maybe just a perception.

===

Just to remind, use "elif" ONLY with the same value which the corresponding "if" uses. Corresponding means the same indentation.
When i corrected your code, Sanae, it got me a "slaveend". I wonder, what would it look like...
I'm terribly sorry, but I am slightly confused. Does that mean I did something wrong with my recent edit, or was my correction right?

If I am wrong, should I write it like this instead?:

Code: Select all

   if refinement  >= 80:
       elif 70 > social_reputation >= 50:
           elif 80 > charisma >= 60:
               elif 70 > fighting_reputation >= 50:
                   elif sin < 50:
                       jump queenend       
   
#GOOD ENDINGS       
   if 80 > refinement >= 50: 
       elif 70 > social_reputation >= 50:
           elif 80 > charisma >=60:
               elif 70 > fighting reputation >=50:
                   elif sin < 50:
                       jump pcend
Or did you mean that all the "elif" be switched to "if"?

The "Slave" ending should DEFINITELY be the one you should get though, so something must be wrong with how I have it versus how you have it.

(And yes, I'm a good girl. :lol:)

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Complicated Points-Based Endings... (cont.)

#10 Post by apricotorange » Sun Jul 29, 2012 10:24 am

Oh, wait, I see what's happening. You have a chain like "if refinement >= 80:", "elif 80 < refinement >= 50: ", "else:". But one of the sub-conditions fails, so you end up falling through past the "else:" (which I'm guessing just happens to contain your "best" ending).

Basically, you don't want to be using elif/else; change all the elif to if, and zap the else.

Sanae
Regular
Posts: 37
Joined: Sat Jul 28, 2012 4:26 pm
Contact:

Re: Complicated Points-Based Endings... (cont.)

#11 Post by Sanae » Sun Jul 29, 2012 10:34 am

apricotorange wrote:Oh, wait, I see what's happening. You have a chain like "if refinement >= 80:", "elif 80 < refinement >= 50: ", "else:". But one of the sub-conditions fails, so you end up falling through past the "else:" (which I'm guessing just happens to contain your "best" ending).

Basically, you don't want to be using elif/else; change all the elif to if, and zap the else.
So in other words, something like this?

Code: Select all

   if refinement  >= 80:
       if 70 > social_reputation >= 50:
           if 80 > charisma >= 60:
               if 70 > fighting_reputation >= 50:
                   if sin < 50:
                       jump kingend       
   
   if 80 > refinement >= 50: 
       if 70 > social_reputation >= 50:
           if 80 > charisma >=60:
               if 70 > fighting reputation >=50:
                   if sin < 50:
                       jump pcend

   jump destituteend
I'm not quite sure why I should remove the "else" though. The "Destitute" Ending is what is included with "else", because it's the worst ending if you don't fit any of the criteria for the other endings. Is there another way to write this then?

(I'm really sorry for asking so many questions, by the way! I'm a newb when it comes to programming, orz.)

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Complicated Points-Based Endings... (cont.)

#12 Post by Levrex » Sun Jul 29, 2012 12:31 pm

Sanae wrote: I'm terribly sorry, but I am slightly confused. Does that mean I did something wrong with my recent edit, or was my correction right?
Or did you mean that all the "elif" be switched to "if"?
Yeah, i meant just that. Your correction is correct (a pun?).

And what's wrong is indentation for conditions and lack of conditions also. You should better refrain from using "elif"-s, they are a tough thing to make work.
Let's see.
We wouldn't pass to the queenend, we don't pass to the pcend, because we lack refinement.
But our KARISUMA is overflowing! So we meet the charisma condition block (which is the third). But we don't meet the social reputation for the third ending...
But, as i just said, we met the "elif charisma >= 80:" condition and we don't have a block to explain which ending to jump to, so we stay at that condition and don't execute others. The label "endings" passes with flying colors, and the next label, accidentally, is "queenend", which the game chops on immediately, due to how it works with multiple-label files. If you remove that label, the game will go to "pcend" label instead, until there are no labels left after the "endings" one.

If you refrain from using "elif"-s, however, all condition blocks will be ran through until you finally jump into the first ending label which meets your stats.
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

Sanae
Regular
Posts: 37
Joined: Sat Jul 28, 2012 4:26 pm
Contact:

Re: Complicated Points-Based Endings... (cont.)

#13 Post by Sanae » Sun Jul 29, 2012 1:36 pm

You guys are the best! I knew it was worth posting here~

Just for clarification, for anyone reading this with the same question, the solution is just as Levrex said: just avoid using elifs since the engine would skip everything else if nothing is met. So one sample of the code would be this:

Code: Select all

   if 80 > refinement >= 50: 
       if 70 > social_reputation >= 50:
           if 80 > charisma >= 60:
               if 70 > fighting_reputation >= 50:
                   if sin < 50:
                       jump pcend
       
   if charisma >= 80: 
       if 70 > social_reputation >= 50: 
           if sin < 50: 
               jump concubineend
       
   if fighting_reputation >= 70: 
       if 70 > social_reputation >= 50: 
           if sin < 50:
               jump knightend
I'm not sure if using "Else" is good or not, but it worked in my case, and it's always good to have something to fall on in case no one meets criterias.

So yeah, I tested it for several endings, and it worked! Thanks guys! I'll mark this topic as "Solved" now. :)

Post Reply

Who is online

Users browsing this forum: No registered users