It was hard to find a good title explaining the issue. I will try to explain the problem in detail. I try to use a single line if statement with 2 actions inside another if statement. However, this usage fails the parent if statement's result.
Before going into deep I have to stress that the method below returns FALSE:
draggedItem.GetComponent<PreparedItem> ().CheckPreparationAvailability ()
The method above is included inside two if clauses below. Therefore I expect the result FALSE immediately. The only changing part is the last statement, focus there.
Problematic version without parentheseses:
if (acceptedTypeID == draggedItem.CurrentTypeID.foodTypePart1
&& draggedItem.GetComponent<PreparedItem> () != null
&& draggedItem.GetComponent<PreparedItem> ().CheckPreparationAvailability () // RETURNS FALSE, DO NOT FORGET
&& rootTransform.GetComponentsInChildren<DragAndDropItem> ().Length <= 0
&& draggedItem.RootTransform.GetComponentInChildren<PlateCell>()
&& (true)? true : true) { // problem here
'if' is considered as TRUE and the inside is executed ...
}
Working version with parentheseses:
if (acceptedTypeID == draggedItem.CurrentTypeID.foodTypePart1
&& draggedItem.GetComponent<PreparedItem> () != null
&& draggedItem.GetComponent<PreparedItem> ().CheckPreparationAvailability () // RETURNS FALSE, DO NOT FORGET
&& rootTransform.GetComponentsInChildren<DragAndDropItem> ().Length <= 0
&& draggedItem.RootTransform.GetComponentInChildren<PlateCell>()
&& ((true)? true : true)) { // WORKS AS EXPECTED
'if' is considered as FALSE which is expected and the inside is NOT executed ...
}
Aucun commentaire:
Enregistrer un commentaire