IF commands

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
the stampede
Newbie
Posts: 3
Joined: Mon Apr 16, 2007 4:12 am
Contact:

IF commands

#1 Post by the stampede »

Hi everyone. I only downloaded the software yesterday but I'm intrigued!! hehe. I was wondering: is it possible to have a value (eg: 'strength') and then have the game refrence that value and branch a conversation accordingly? Just as an eample: if strength = 1 then "the bolder dosent move", if strength > 1 "you move the boulder". I have searched the helpfiles and I cant seem to get this to work. Can anyone help?

denzil
Veteran
Posts: 293
Joined: Wed Apr 20, 2005 4:01 pm
Contact:

#2 Post by denzil »

Yes, it's possible. You can store value this way (strength - the name of the value is called variable):

Code: Select all

$ strength = 1
And if you want to compare the variable to some value you do it:

Code: Select all

if strength < 10:
	"You are weak."
if strength == 10:
	"You are strong"
if strength > 10:
	"You are very strong"

Note that for assigning value to variable ONE equal sign is used but for testing if variable is equal to some value TWO equal signs are used.
You can find out more here: http://renpy.org/
Practice makes purrrfect.
Finished projects: Broken sky .:. colorless day .:. and few more...

Hime
Veteran
Posts: 384
Joined: Thu Jun 01, 2006 12:46 pm
Projects: Project Nattsu, Take Rena Home
Contact:

#3 Post by Hime »

Oh and, if you want to continue the story only if the character is strong enough to move the border and thus for example enter a cave, or something alike, you could do something like...

Code: Select all

   if strenght < 10:
      "You aren't strong enough to move the boulder."
   if strenght == 10:
      "Using all of your strenght, you push the boulder aside."
      jump cave
   if strenght > 10:
      "You push the boulder aside with ease."
      jump cave
I don't know if this is the absolutely wisest thing to do since I'm quite much a Ren'Py newbie myself, but at least it works... I think. And then you continue the story in the label "cave":

Code: Select all

label cave:
   "The cave is very dark and quite scary."
   "And then blah blah blah, blah blah blah..."

the stampede
Newbie
Posts: 3
Joined: Mon Apr 16, 2007 4:12 am
Contact:

#4 Post by the stampede »

Thanks you two but I have tried this already and I keep getting the error message:

if statement expects a non-empty block.

Do you have any idea why?

J13
Regular
Posts: 60
Joined: Wed Jan 24, 2007 3:28 am
Location: Cambridge
Contact:

#5 Post by J13 »

I've come across that one lots before. It might be an indentation problem, if you look at the line it mentions in the traceback it will probably look something like this

Code: Select all

    if strength > 1:
    jump here
when it should look like this

Code: Select all

    if strength > 1:
        jump here

Counter Arts
Miko-Class Veteran
Posts: 649
Joined: Fri Dec 16, 2005 5:21 pm
Completed: Fading Hearts, Infinite Game Works
Projects: Don't Save the World
Organization: Sakura River
Location: Canada
Contact:

#6 Post by Counter Arts »

If you make an if statement, you need to put something in it. Otherwise it throws that error at you.

the stampede
Newbie
Posts: 3
Joined: Mon Apr 16, 2007 4:12 am
Contact:

#7 Post by the stampede »

Hehe, thanks j13, it was the indent. It now alows me to compile it and play the game but when I play throught to that point I get the same error message??

Post Reply

Who is online

Users browsing this forum: Google [Bot], voluorem