Numeric Options [Solved]

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
Skiegh
Regular
Posts: 38
Joined: Mon Dec 19, 2011 2:47 pm
Contact:

Numeric Options [Solved]

#1 Post by Skiegh »

Hello there once again.

This time I need help figuring out exactly how you go about making alternate routes depending on a numeric value that has been increasing or decreasing depending on previous actions. My attempts at doing so have resulted in nothing ideal, to the say least.

Example of what I need is:

Let's say...

-Anything 25 or greater goes on this path.
-Anything equal to or less than (or I suppose greater than) -25, goes on this path.
-Anything between 25 and -25 goes on this path.

That's essentially what I am trying to do. However, regardless of values, it seems to want to go on wrong paths. Any help on the code necessary for the above would be really helpful. I assume I am just using Or and And statement incorrectly but I could be wrong.

Thanks in advance.
Last edited by Skiegh on Sun Apr 21, 2013 12:01 pm, edited 1 time in total.

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: Numeric Options

#2 Post by kankan »

Try using if statements:

Code: Select all

if myvalue >= 25:
    jump path1

elif myvalue <= -25:
    jump path2

else:
    jump path3

Skiegh
Regular
Posts: 38
Joined: Mon Dec 19, 2011 2:47 pm
Contact:

Re: Numeric Options [Solved]

#3 Post by Skiegh »

kankan wrote:Try using if statements:

Code: Select all

if myvalue >= 25:
    jump path1

elif myvalue <= -25:
    jump path2

else:
    jump path3
That had the desired effect, thank you. (I was close, I just didn't know about that elif statement, which I assume is short for ElseIf. Useful to know!)

Wouldn't mind knowing how to actually use an And statement for a similar solution just to know for future reference however. Say instead of just the else statement for the third option, it wanted to dictate exactly that you were above -25 and below 25, how would I code that exactly? I like to know these things so I don't have to pry for more information.

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: Numeric Options [Solved]

#4 Post by kankan »

Yeah, Python's elseif clause is a little weird... If you want the third option to be both of the previous two, you'd have to put that as the first if (otherwise Python will just see that the variable fits the first, more general condition and ignore the specific one you want). So something like this:

Code: Select all

if a >= 25 and b <= -25:
    jump somewhere

elif a >= 25:
    jump somewhereelse

elif b <= -25:
    jump anotherplace

else:
    jump lastresort
The "and" statement will work pretty much as you expect it to. Same goes for "or" and "not."

Post Reply

Who is online

Users browsing this forum: Ocelot