"and" and "or" in renpy

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
User avatar
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

"and" and "or" in renpy

#1 Post by Evildumdum » Fri Jan 22, 2016 5:23 pm

so i have a little snippet of code that no matter what way i look at it, should work. But it doesn't. I can only assume im getting something obvious and fundamental wrong.

Code: Select all

if map[msy][msx+1][3] and map[msy-1][msx+1][3] and map[msy-2][msx+1][0] == race_moving or 0:
This piece of code is designed to check if the tiles in between the start point and destination for a unit on a campaign map (2D list format) is obstructed. This is just one route but it serves as a good example since they are all essentially the same plus or minus a few digits.

The msx/msy variables are the x and y start co-ordinates on the grid and the [3] is the indicator in that squares data that indicates what is occupying it. 0 being unoccupied and any other integer indicating the attached race. The idea is that a unit can move through any tile that contains either its own race or nothing. If a tile on the given route is obstructed by another race or impassable object then that route is not possible.

The thing is, even when all the conditions are met i.e. all of the tiles are empty with a value of 0, it still returns False. Am i using the "and" and "or" functions incorrectly and is there a better way of doing this at all?
"If at first you don't succeed, try hitting it with a shoe."

User avatar
chocojax
Miko-Class Veteran
Posts: 702
Joined: Sun Oct 25, 2009 11:27 am
Completed: http://art.jphi.me/projects
Projects: Umbra, Familiarity, Maleficent Justice
Organization: spaceNote
Tumblr: chocojax
Github: jenniferphi
Location: California
Contact:

Re: "and" and "or" in renpy

#2 Post by chocojax » Fri Jan 22, 2016 6:52 pm

You need to think of 'and' and 'or' statements as if you're stringing along multiple if statements.
So, what your current statement looks like is:

Code: Select all

if map[msy][msx+1][3]
and
if map[msy-1][msx+1][3]
and
if map[msy-2][msx+1][0] == race_moving
or
if 0:
And just so you know, it's probably returning false because of the last statement (if 0 returns False, and if 1 returns True).

I'm on my phone right now so I can't write a detailed fix, but it should be something like:

Code: Select all

if (map[blah] == race_moving or map[blah] == 0) and (map[blah2] == race_moving or map[blah2] == 0)
I'm not entirely sure what you were checking for with the 0, but it should follow something like this.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]