- Home /
Functions with variables
How would I leave the "bool x" or in other case the "bool y" unchanged and just change the opposite variable to only affect one change?
void Move(int t)
{
if(t == 0)
{
VoidName("no change", true);
}
else
{
VoidName(true, "no change");
}
}
void VoidName(bool x, bool y)
{
}
Comment
Sure I'm bite, whats that catch?
private const bool FOO=false;
public static bool Y=false,X=false;
void $$anonymous$$ove(int t) {
if(t == 0) {
//Y is changable but X= constant.
OptionChoice(FOO, Y);
} else{
//X is changable but Y= constant.
OptionChoice(X, FOO);
}
}
void OptionChoice(bool x, bool y)
{
if(x){
//Do Something Grand.
} else {
//Do Something $$anonymous$$ediocre but efficient.
}
if(y){
//Do Something Evil.
} else {
//Do Something poor and inefficient.
}
}
What is the value of the "no change" bool supposed to be? right now there is no predefined value you could keep. What are the two bools supposed to do in VoidName?
Answer by SteenPetersen · Feb 21, 2019 at 08:19 AM
Im going to guess that what you are referring to here is to have optional parameters in a function/Method?
Basically in your case I believe a better option would be:
if(t == 0)
{
VoidName(true);
return;
}
VoidName(false);
and then have your VoidName Method:
void VoidName(bool b)
{
if(b)
{
// do something
return;
}
//do something else
}