I have this:
private bool CheckHandleCompleteEmpty()
{
for (int i = 0; i < pickupHandleComplete.Length; i++)
{
if (!pickupHandleComplete[i])
{
return true;
}
}
return false;
}
It should check each pickupHandleComplete is empty as:
free1 = CheckHandleCompleteEmpty();
and shorthand:
free1 = (!(pickupHandleComplete[0]) && !(pickupHandleComplete[1]));
and return free1 as true if they are - it isn’t working for me although I’ve used this a few times, and is always returning nothing.
What do you mean by returning nothing?
If I understand correctly (and I’m not sure that I do), your method is supposed to tell you if all elements of the array are false? If that’s what you want, your logic is not right. You’re bailing out and returning true as long as you find any false element in the array.
What you want to do is bail out if you find any true element in the array:
private bool CheckHandleCompleteEmpty()
{
for (int i = 0; i < pickupHandleComplete.Length; i++)
{
if (pickupHandleComplete[i])
{
return false;
}
}
return true;
}
Sorry, I mean pickupHandleComplete is never true in this case - I currently have two elements in the array, which can have any amount of elements - I’m trying to detect if any element pickupHandleComplete is true - but it’s never returning false or true in that routine.
That’s not possible – if the method is getting called, it’s either returning false or true.
Then it would be like this:
private bool CheckHandleCompleteEmpty()
{
for (int i = 0; i < pickupHandleComplete.Length; i++)
{
if (pickupHandleComplete[i])
{
return true;
}
}
return false;
}
But what on earth do you mean by “it’s returning nothing”?
1 Like