#My switch keeps on returning values that shouldn't be possible

1 messages · Page 1 of 1 (latest)

supple goblet
#

...Look man, I'm no expert in programming, but I've been trying to make an undertale-like battle system for a small easter egg, but for some reason, FOR SOME REASON, the switch I'm using keeps on returning non-sensical values? I checked if it's getting referenced or double called everywhere in the project but nothing, Here's the code in question, & here's the behavior that's happening :

#

& here's the code that's responsible for getting the attack ```cs
private int curAttack = -1;
public IEnumerator GetAttack()
{
curAttack++;
curAttack %= 7;
Debug.Log(curAttack);
return curAttack switch
{
1 => ZaryTwo(),
3 => ZaryFour(),
5 => ZaryThree(),
6 => ZaryFive(),
7 => ZarySix(),
_ => ZaryOne(),
} ;

}```
#

ZaryOne-ZarySix is the coroutines that are used for the attacks

#

I've been trying to fix this issue for the past 3 days, so please help-

young wasp
#

Well if they're coroutines you'd have to be using StartCoroutine()? Right?

supple goblet
young wasp
#

Well tbh, I dont even fully understand this code, so I wouldn't know. But good luck on finding it

#

Ask ChatGPT

supple goblet
#

maybe it'll help?

#

¯_(ツ)_/¯

young wasp
#

Tbh, helps me a lot lol. Sometimes it can be good at trouble shooting, sometimes not...

supple goblet
#

yeah, from my experience it's been a hit or miss

#

welp, it wasn't that useful, it seems like even chat gpt is just as confused as I am

#

what's really making me question this, is that it's not repeatable, Like it happens sometimes, & then works as expected in other times

#

I've never seen said behavior in a while

tawny kettle
supple goblet
tawny kettle
#

excellent, glad you managed to get it solved 🙂