Storing variables and such

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
dm251
Newbie
Posts: 18
Joined: Thu Nov 18, 2010 8:54 pm
Location: Hiding in your Closet
Contact:

Storing variables and such

#1 Post by dm251 »

I've been trying on doing things such as this one...

like setting a variable for counting.
e.g

Code: Select all

set count = 0
later, when choices are made from a menu, the count adds another point,
like

Code: Select all

count = count + 1
until such that on the last part using an if statement to determine if the player will get a good or bad ending...
I' tried practicing that very idea but I'm a bit unfamiliar with Ren'Py.

Would be great if someone can tell me on how to do it . :D

Incendium
Regular
Posts: 25
Joined: Wed Dec 09, 2009 12:57 am
Contact:

Re: Storing variables and such

#2 Post by Incendium »

The Ren'Py language doesn't support setting variables (except in special cases), but Python does. You can turn a Ren'Py statement into a Python statement by prefixing it with "$" or putting it in a "python:" block.

Code: Select all

"Greetings, user!"
menu:
    "Where do you want to go?"
    "Here":
        $ count = 1
    "There":
        $ count = 2
"Your count is currently %(count)d."
python:
    count += 1
"Your count is now %(count)d."

dm251
Newbie
Posts: 18
Joined: Thu Nov 18, 2010 8:54 pm
Location: Hiding in your Closet
Contact:

Re: Storing variables and such

#3 Post by dm251 »

Oooohh... So thats how it works.. Thanks dude :D

but if I used the ifs? How would I do it that way?

broken_angel
Veteran
Posts: 322
Joined: Sun Oct 03, 2010 11:49 pm
Completed: Memoirs of an Angel (2010)
Projects: Memoirs of an Angel (Remake); W.I.S.H
Location: United States
Contact:

Re: Storing variables and such

#4 Post by broken_angel »

As in...

Code: Select all

if count == 4:
    "Stuff happens here."
Yes, that works. C:
You can also do "count < 4", "count > 4", or combine statements like "count > 1 and count < 4"

dm251
Newbie
Posts: 18
Joined: Thu Nov 18, 2010 8:54 pm
Location: Hiding in your Closet
Contact:

Re: Storing variables and such

#5 Post by dm251 »

Whoah. Thanks again :D
I'll ask another question whenever I'm in trouble again then :D

dm251
Newbie
Posts: 18
Joined: Thu Nov 18, 2010 8:54 pm
Location: Hiding in your Closet
Contact:

Re: Storing variables and such

#6 Post by dm251 »

Err.. I had a trouble again.

I did it like this

Code: Select all

      
"So. I walked to the rooftop."
    $ Sneak = True

        if Sneak = True
            "Mah, Its not bad to stay here for a while...{p}The wind is so refreshing today huh?"
and when I test it...
It goes

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.

On line 182 of C:\renpy-6.11.2\Games\--\---/game/script.rpy: reached end of line when expecting ':'.
if Sneak = True

On line 129 of C:\renpy-6.11.2\--\---/game/script.rpy: invalid syntax
$ Sneak = True
What do I do? I tried what I can but I never fixed this one :?:

fortaat
Regular
Posts: 183
Joined: Tue May 18, 2010 1:16 pm
Contact:

Re: Storing variables and such

#7 Post by fortaat »

Add colon after 'True':

Code: Select all

      
"So. I walked to the rooftop."
    $ Sneak = True

        if Sneak = True:
            "Mah, Its not bad to stay here for a while...{p}The wind is so refreshing today huh?"

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Storing variables and such

#8 Post by Showsni »

Grr. Google Chrome ate my post.

Er hem. Like it says, you're missing a colon; for checking things with if, you need to end in a colon and indent the next line. You also need to use double equals sign for checking things. So,

Code: Select all

if Sneak == True:
            "Mah, Its not bad to stay here for a while...{p}The wind is so refreshing today huh?"
Note that for True and False you can just leave out the equals signs if you want and do:

Code: Select all

if Sneak:
            "Mah, Its not bad to stay here for a while...{p}The wind is so refreshing today huh?"
See here for more help:
http://www.renpy.org/wiki/renpy/doc/tut ... er_Choices

dm251
Newbie
Posts: 18
Joined: Thu Nov 18, 2010 8:54 pm
Location: Hiding in your Closet
Contact:

Re: Storing variables and such

#9 Post by dm251 »

I see...

Yay it works. :D

Thanks a bunch Showsni and Fortaat

Post Reply

Who is online

Users browsing this forum: Andredron