Skip to content

Thoughts on not returning from method (StateMachine) #2

Description

@clankill3r

https://github.com/wangchen/Programming-Game-AI-by-Example-src/blob/master/Buckland_Chapter2-State%20Machines/WestWorld1/MinerOwnedStates.cpp#L60

In the StateMachine for EnterMineAndDigForNugget there is the following:

//if enough gold mined, go and put it in the bank
if (pMiner->PocketsFull())
{
pMiner->ChangeState(VisitBankAndDepositGold::Instance());
}

if (pMiner->Thirsty())
{
pMiner->ChangeState(QuenchThirst::Instance());
}

Now I wonder, wouldn't it be better to return on after the lines where ChangeState is called.
Cause now for example if the miners pockets are full it would go to the bank.
But if the miner is also thirsty, then the if statement for that block is still executed.
This will change the state to QuenchThirst from the bank location.
This could lead to really unexpected behaviour.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions