Variable ranges?

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
Mallamun
Newbie
Posts: 2
Joined: Thu Jun 07, 2007 6:40 pm
Location: Norway
Contact:

Variable ranges?

#1 Post by Mallamun »

Attack of the Newbie Question That Has Probably Been Asked A Million Times Before!

When adding and subtracting numeric variables ($ variable +/-= x), how do I get it to +/- a random number within a given range instead of a fixed value?

Likewise, when customizing endings, instead of operating purely on a <, >, = structure, can I get it to access certain endings if a variable falls within a certain range? 'If variable = 12-13 jump A, 14-25 jump B' type of thing?

More on a Helping Me Think Ahead note, is it possible to define endings based on more than one variable? Ex., both variable A and variable B need to fall within a certain range, or two mutually exclusive ranges, to get ending 1, else ending 2?

Thank you ahead of time for the generous newbie coddling. *Cough*
~Meddle not in the affairs of Dragons, for thou art crunchy and taste good with ketchup.

absinthe
Regular
Posts: 194
Joined: Sat Dec 10, 2005 12:26 am
Contact:

#2 Post by absinthe »

Okay, I'll take a stab at the easy one.

Code: Select all

    # number between 1 and 10, inclusive (I think)
    $ rand_number = renpy.random.randint(1, 10)
    $ number += rand_number
    # number is now number plus random number
There are a few different random functions at the very bottom of chapter 7 in the manual, too.

For ranges, I've always used cascading if/elif/else statements (in Python, anyway). Don't know if there's an easier way to do it?

And, for your last question, you can join clauses with "and" and "or" although I've heard there's some complicated behavior in Python. Boolean logic (okay, any kind of logic) isn't my forte, so I've never really gone much past very simple 'and' statements. :)

Code: Select all

    if ending_points == 10 and special_end == True:
        "Ending points is equal to 10 and special end is True."
    else:
        "Either ending_points is less than 10 or special_end is False."
(Someone more knowledgeable should be along shortly. And I like your sig!)
My 2007 NaNo entry: Eidolon

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

Re: Variable ranges?

#3 Post by J13 »

Mallamun wrote: Likewise, when customizing endings, instead of operating purely on a <, >, = structure, can I get it to access certain endings if a variable falls within a certain range? 'If variable = 12-13 jump A, 14-25 jump B' type of thing?
I wanted to do something similair myself a while back, sadly the only way to do this is to use > ,< with 'and'
for example

Code: Select all

    if score > 0 and score < 5:
        jump outcomea
    if score > 4 and score < 9:
        jump outcomeb
It may not be pretty to look at but it should work.

Mallamun
Newbie
Posts: 2
Joined: Thu Jun 07, 2007 6:40 pm
Location: Norway
Contact:

#4 Post by Mallamun »

Thank you both : )

Is there a rule for how many "and"s I can use? Could I for example say, If scoreA < 4 and scoreB > 8 and scoreC == 6 jump ending_blah?
~Meddle not in the affairs of Dragons, for thou art crunchy and taste good with ketchup.

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

#5 Post by monele »

Infinite

Post Reply

Who is online

Users browsing this forum: No registered users