Hi people.
Well, unity has been throwing to me an error:
Assets/Battle.cs(822,17): error CS0151: A switch expression of type `float’ cannot be converted to an integral type, bool, char, string, enum or nullable type
This particular error.
As I know, this means that I’ve been treating the variable of a switch not as a float;
switch (multipliers [0]) {
case 1f:
_multiplier = multipliers [1];
return _multiplier;
break;
case 0.5f:
switch (multipliers [1]) {
case 1f: _multiplier = multipliers [0]; return _multiplier; break;
case 2f: _multiplier = 1f; return _multiplier; break;
case 0.5f: _multiplier = 0.25f; return _multiplier; break;
case 0f: _multiplier = 0f; return _multiplier; break;
}
break;
case 2f:
switch (multipliers [1]) {
case 1f: _multiplier = multipliers [0]; return _multiplier; break;
case 2f: _multiplier = 4f; return _multiplier; break;
case 0.5f: _multiplier = 1f; return _multiplier; break;
case 0f: _multiplier = 0f; return _multiplier; break;
}
break;
case 0f:
_multiplier = 0f;
return _multiplier;
break;
}
In this particular switch.
But the problem is, that I can’t see where is the mistake. So, if anibody see something weird, I’ll apreciate the help.
(Sorry for my spelling and…)
Thank you very much.
It’s saying you can’t use a float for a switch.
I don’t know what you’re doing here, but it looks really weird and wrong. Also, you don’t need a break after a return in a switch.
Nice!!
All you just say is true xD
1- I changed the array of floats for an array of strings and it worked.
2- True, no need to put all of those returns, so I put just one of them at the end of the function.
3- I’m trying to calculate the multiplier for the damage in a pokemon based game, and it depends on the type of the attack and the types of the foe, so I’ve made a switch that stores the multiplier of the both types that the pokemon can have following this table:
And what the problem-maker switch does, is read the two multipliers and transform them in a value that can be: x0, x0.25, x0.5, x1, x2, x4. Depending on which of those two options were.
Well enough talking meaningless things xD
Thanks for your fast and right answer
EDIT: Allright I just realized that what this switch does its multiply the two multiplies but in a intrincate and weird form xD
So, all this work was in vain. Yay.
Why not just put the data into a 2D array, and get it out with a simple lookup? Replace your entire unmaintainable switch statement with a couple of lines of code.
Well as you can see I’m pretty newbie in programing, and I didn’t know about the existence of the 2D array xD
A 2D array is way smarter than the switch that I have ant it cost like 200 lines less, so thanks about that answer. But, What’s a lookup?
Again thanks.