Thread: Reading C code
View Single Post
Old August 2, 2018, 13:02   #15
Quirk
Swordsman
 
Join Date: Mar 2016
Posts: 293
Quirk is on a distinguished road
Quote:
Originally Posted by wobbly View Post
So I can find if/thens in the code but none apear to be nested. How is this generally handled?
Mostly if you're checking two conditions that both have to be true you would use AND (&&) e.g.
Code:
 
if (monster_is_awake && monster_sees_you)
{
}
however you would nest ifs in cases where you want to do one of two or more things when a condition is true e.g.
Code:
 
if (monster_is_awake)
{
    if (monster_sees_you)
    {
        do_monster_attack();
    }
    else
    {
        do_monster_wander();
    }
}
To keep logic from getting too awkwardly nested, the inner logic may be moved into functions - so you might actually see the inner if moved into a do_monster_awake function in practice.
Quirk is offline   Reply With Quote