Unity not understanding tuples
my code is
switch ((Coralator.BlockIn(MovmentToVector(), mov) != null), (Coralator.BlockIn(MovmentToVector(), mov).PartContainer.PartAttributeCheck(Part.PartAttribute.Unenterable) && !Coralator.BlockIn(MovmentToVector(), mov).PartContainer.PartAttributeCheck(Part.PartAttribute.Pushable)))
{
case (false, _):
{
PartMov(mov);
break;
}
case (true, true):
{
PartMov(mov);
break;
}
case (_, _):
{
break;
}
}
and the c# compiler says it's fine and unity states that it has 14 errors. i tried adding a semicolon in the end and removing the curly brackets inside the cases. help?
Answer by streeetwalker · Mar 09, 2020 at 07:14 AM
See this discussion: https://stackoverflow.com/questions/44355630/how-to-use-c-sharp-tuple-value-types-in-a-switch-statement/50768183
thanks, i tried it and it still didn't help, now it has 17 errors
switch ((Coralator.BlockIn($$anonymous$$ovmentToVector(), mov) != null), (Coralator.BlockIn($$anonymous$$ovmentToVector(), mov).PartContainer.PartAttributeCheck(Part.PartAttribute.Unenterable) && !Coralator.BlockIn($$anonymous$$ovmentToVector(), mov).PartContainer.PartAttributeCheck(Part.PartAttribute.Pushable)))
{
case var t when t.Item1 == false:
{
Part$$anonymous$$ov(mov);
break;
}
case var t when t==(true, true):
{
Part$$anonymous$$ov(mov);
break;
}
}
can you help me?
Sorry, razivo! Without seeing all the relevant code and all the errors, there is now way to tell from here what possibly might be going wrong.
It looks like you are only checking 3 compound conditions. Why not write them as if else statements?
The fact that the compiler passes your original code indicates the problem is with the objects you're checking.
Null is always a bugger. One element of your tuple checks if the object is null, but if it is you are guaranteed to generate errors on any statements that deal the other element!
You'd be better off wrapping the whole thing in an if to make sure Coralator.BlockIn($$anonymous$$ovmentToVector(), mov) != null
thanks! the errors are not runtime errors, ins$$anonymous$$d they are compiler ones i.e. semi-colons and curly brackets. i decided to make it an if else statement, thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612224628im_/https://answers.unity.com/themes/thub/images/avi.jpg)