State controlled?

Confusing Babble Allert!! ( This happens when you look at something to long and know it should work even when you know it wont.)

I have been trying to get two var : boolean’s checkboxes in Unity’s inspector that are controlled by a script to be in one of 3 states. Both cond1 cond2 false,cond1 true cond2 false,or cond2 true cond1 false… Setting both to be false is no problem, but making one be true and forcing the other to be false and making the check box locked out until the first box has been unchecked is proving to be problematic. I’ve tried isolating everything in nested if() functions with no success, and as I keep looking at it I’m seeing that it s won’t work the way I want using this method. I’m just not sure how to go about this. Here is a pseudo example.

It should execute in the inspector like this.

State 0 = cond1 false, cond2 false
State1 = select either cond1 or cond2 and make the selected true and the other false.
State 2 = with State1 active be able to select the cond# that is not true and set it to be true and the other to be false.
State 3 = Revert back to state 0;

var UseCond : boolean;
var Cond1 : boolean;
var Cond2 : boolean;

Function Update(){

If(!UseCond){
Cond1 = false;
Cond2 = false;
}
//Something to set State1 and State2

//This is what i was trying. I know will not work the way i want it too.

if(Cond1  !Cond2){
Cond2 = false;
//Do Something
}

if(Cond2  !Cond1){
Cond1 = false;
//Do Something
}

}

// When doing it this way both boolean checkboxes can still be checked at the same time. The ultimate question is how can i lock the checkbox that is false while the other is true?

Did i just answer my self? Should i be using while() instead of if() ?

If you’re going to use states, I would suggest actually using states (an enum), and not booleans.

Here is a simple example of how to use an enum to make a very basic state machine:

//state setup
enum aiState{ wandering, chasing, attacking }
var state : aiState;

function Update(){

	//perform logic to determine what aiState state should be in
	//I am just going to set it to wandering to illustrate enum syntax
	state = aiState.wandering;

	if(state == aiState.wandering){
		//do wandering stuff
	}
	else if(state == aiState.chasing){
		//do chasing stuff
	}
	else if(state == aiState.attacking){
		//do attacking stuff
	}

}

Fantastic! I love learning something new. When i get home i’m going to adapt this and give it a try. Thanks so much for the advice. :slight_smile: