GameMaker Nested if statements

Sorry, this a bit of a newbie question but I'm cleaning, house as much as possible. Hence several posts over that past few days.

What is the best way to deal with nested if statements?

if the weather is dry < if im at home < if im not tired < if i have no work that day < if today is not sunday < if i'm not dead < go to the park >> > > >

How can I make these less ugly?

zendraw

Guest
ugly? this is beutiffle, but where are the elses, then it becomes even more beutiffle

FrostyCat

Redemption Seeker
GMC Elder You should have been taught long ago to use && for this kind of setup.
if (condition1 && condition2 && condition3 && condition4)

ophelius

Rising Star
if(weather == dry && at_home && !tired && work == 0 && day != Sunday && !dead) destination = park;

zendraw

Guest
You should have been taught long ago to use && for this kind of setup.
if (condition1 && condition2 && condition3 && condition4)

this is not aways the case, meny times you will nest ifs becouse you need to calculate stuff in the middle. espetially for games its better to nest then to stack. you cant expand with if (&&&&&&&&), the resault will be one, and in the other case the resault will vary.

ophelius

Rising Star

this is not aways the case, meny times you will nest ifs becouse you need to calculate stuff in the middle. espetially for games its better to nest then to stack. you cant expand with if (&&&&&&&&), the resault will be one, and in the other case the resault will vary.

I agree, sometimes you have conditions that shouldn't be checked unless some other condition is true:

if(condition1) < if(condition2 & condition3)< >>

Daniel Mallett

Forum Adept

I don't believe I should have been taught this at all. That's just as ugly. It's just one really big line and yes I know how to use and 'and' &&. You can multi-line it yes but it's the same logical statement.

Zendraw. This was just an example I regret using this example now because it made it sound as though I were reading a textbook for the first time. What I mean is if I had100 conditions. This is an exaggeration but lets say you genuinely needed to check lots of items would you do if this == that && this && that && this && that && this && that && this && that && this && that && this && that && this && that && this && that && this && that && this && that && this && that && this&& that.

I don't mean I could use a case statement. Which I'm sure is coming. If this is that but not that but is this unless that is not this and so on.

I don't think I'm making myself clear. I think this is my biggest problem when asking questions. I'll have to re-think how I'm going to ask this. It makes me sound like a total newb. It's frustrating as hell.

Are you saying if you had 100 conditions even ones with other logical operators we might have not just && but || and ! and ^^. How do we make this readable?

if (condition1 && condition2 && condition3 && condition4 && condition5 && condition6 && condition7 && condition8 && condition9 && condition10 && condition11 && condition12 && condition13) < . >This is good is it. Maybe I don't know it dosen't feel right.