Page 1 of 1

How do I track points?

Posted: Tue Jun 05, 2007 10:21 am
by m_evergreen
If I want to keep track of something in my game as a number and add and subtract from it what is the proper method? Would this be right?

$ dex = 10

menu exercise:
"dance":
$ dex = dex + 3
"walk":
$ dex = dex + 1
"sit and watch people":
$ dex = dex - 2

Would that set dex to 13, 11 and 8 respectively? Or will it just give me a bunch of errors? If it won't work what's the proper format?

Thank you,
-M

Posted: Tue Jun 05, 2007 10:40 am
by PyTom
That'll work when indented properly:

Code: Select all

$ dex = 10

menu exercise:
    "dance":
        $ dex = dex + 3
    "walk":
        $ dex = dex + 1
    "sit and watch people":
        $ dex = dex - 2 

Posted: Tue Jun 05, 2007 10:40 am
by Guest
That woudl work, you could use this also. It does exactly the same thing so it's just a matter of preference

$ dex = 10

menu exercise:
"dance":
$ dex += 3
"walk":
$ dex += 1
"sit and watch people":
$ dex -= 2
and you'll get the same effect.

On another note if you ever want to check the value in game you can use this in the game and it will read out the value as dialoge.

Code: Select all

'%(variablename)s'
so for example

Code: Select all

'I have %(dex)s points'

Posted: Tue Jun 05, 2007 11:23 am
by m_evergreen
Thank you PyTom, I thought I'd indented it but my spaces disappeared when I posted. But I've forgotten to indent properly several times since starting to use Ren'Py, and the colons...

Thank you too Guest, that's great to know! I'm pretty sure I'll need your other code as well.

-M

Posted: Tue Jun 05, 2007 12:32 pm
by Jake
m_evergreen wrote:Thank you PyTom, I thought I'd indented it but my spaces disappeared when I posted.
It's a quirk of HTML - which web pages are marked up in - that any amount of whitespace in the source document is displayed as a single breaking space when rendered. This allows people to write indented and easy-to-edit HTML without it looking weird when people see the document.

Thus, if you want to display carefully spaced text (such as indented code) on the web you need to use something like the 'preformatted text' element (<pre>), which is accessed on the forum using the 'code' tag.

Posted: Tue Jun 05, 2007 12:59 pm
by chronoluminaire
Just to note: the code Guest provided is used for string variables. For numeric variables, you need to use this version:

Code: Select all

'%(variablename)d'
- the "d" is short for "decimal". But actually you often won't need that, for internal counters - you can include any amount of Ren'Py code in the branches of your "if" statement, including "jump"s to special bonus bits of script :)