...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 :
#My switch keeps on returning values that shouldn't be possible
1 messages · Page 1 of 1 (latest)
& 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-
Well if they're coroutines you'd have to be using StartCoroutine()? Right?
true, but this is a scriptable object
Well tbh, I dont even fully understand this code, so I wouldn't know. But good luck on finding it
Ask ChatGPT
fair enough
Hmm, yeah I'll go & ask chat gpt
maybe it'll help?
¯_(ツ)_/¯
Tbh, helps me a lot lol. Sometimes it can be good at trouble shooting, sometimes not...
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
You showed us a video, and you showed us the code but you haven't explained why you believe the the switch has nonsensical values. The video shows a 5, and then a 6. What's the problem with that ?
I did manage to fix the issue (by changing it from a scriptable object to a static class), the issue was that instead of going from 0 to 1, 2,3,4 (and so on), it just skipped straight to say, 4
excellent, glad you managed to get it solved 🙂