Help? Trying to use Else, If and Elif Statements in Renpy

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
ODDESTY
Newbie
Posts: 2
Joined: Sun Mar 13, 2016 8:09 pm
Deviantart: ODDESTY
Contact:

Help? Trying to use Else, If and Elif Statements in Renpy

#1 Post by ODDESTY » Thu Mar 31, 2016 6:38 pm

Hi All!

So I've lately been trying to work on a practice visual novel in RenPy, and I'm trying to get my point system to work. Here's what I've written:



init:

#Points system
$ points = 0
$ points_max = 100

if points >= 70:
jump best_ending
elif points >= 50:
jump good_ending
elif points >= 30:
jump bad_ending
else:
jump worst_ending

# Declare characters used by this game.
$ x = Character(' ', color="#c8ffc8")
$ e = Character ('Ella', color="#c8ffc8")

#The game starts here.
label start:

e "AHHH!"

____________________________

It all seems fine and dandy and will bring up the game menu, but as soon as I click 'Start game' an error window pops up saying that "Sayer e is not defined"


You can see clearly above that I have in fact defined 'e' as the sayer (speaker) Ella.

Now when I remove my point system and launch it, without touching where I define Ella as a speaker, everything goes smoothly. but of course, I don't have my point system anymore.


Can anyone help with this problem?

User avatar
Marionette
Regular
Posts: 128
Joined: Thu Apr 21, 2011 12:04 pm
Completed: https://marionette.itch.io/
Projects: Get Meowt of Here
Deviantart: rexx9224
itch: marionette
Location: Ireland
Discord: Marionette#2995
Contact:

Re: Help? Trying to use Else, If and Elif Statements in Renp

#2 Post by Marionette » Thu Mar 31, 2016 7:49 pm

Try changing
$ x = Character(' ', color="#c8ffc8")
$ e = Character ('Ella', color="#c8ffc8")

to

define x = Character(' ', color="#c8ffc8")
define e = Character ('Ella', color="#c8ffc8")

and see if that helps.



Edit:

Think i figured out the issue. You shouldn't have your if statement in the init block. The game is basically jumping to the ending labels before it has set up the characters, right as the game starts, as the jumps are in the init block.

Put your if ending check in a separate label and then call into it when your game gets to the point of choosing an ending.

User avatar
ODDESTY
Newbie
Posts: 2
Joined: Sun Mar 13, 2016 8:09 pm
Deviantart: ODDESTY
Contact:

Re: Help? Trying to use Else, If and Elif Statements in Renp

#3 Post by ODDESTY » Thu Mar 31, 2016 8:35 pm

That seemed to have worked.

Thank you very much ^_^ I have been crawling into a ball of frustration over this for days.

I truly appreciate it.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Help? Trying to use Else, If and Elif Statements in Renp

#4 Post by Onishion » Thu Mar 31, 2016 10:46 pm

Were you intending that by putting the if statements in the init that it would get checked constantly and automatically trigger if the conditions were met? If so, that wouldn't do that, and the actual way to do that is kind of complicated. It'd probably be best to put that in its own label, like:

Code: Select all

label CheckEnding:
    if points >= 70:
        jump best_ending
    elif points >= 50:
        jump good_ending
    elif points >= 30:
        jump bad_ending
    else:
        jump worst_ending 

# and then when you want to reach the ending, just. . .

    jump CheckEnding

oh, and put code in [-code-] blocks, minus the -'s, to retain indents.

Post Reply

Who is online

Users browsing this forum: Alex, Google [Bot], nyeowmi