Closed destilla closed 8 years ago
I'll have some free time today in about an hour, so I'll take a look at what I did wrong
Hm, that's a bit strange. Also I noticed that the WSU QB's name is for both of those turnovers (even though its not his team for one of them), but I think I've seen that before so your change probably wouldn't have caused that. Its a weird bug I couldn't figure out.
Easier to fix than I thought. Here's what happened in the screenshot above (TLDR is at the bottom):
WSU failed on 4th down. It wasn't actually 4th and 5 because I don't log the turnover on downs until after 4th down has failed, and by then "Yards to go" has been updated. Regardless, they failed on 4th down, the log shows how many yards they had left to go after they ran 4th down, and what the time on the clock was when 4th down ended.
So runPlay(offense,defense) = runPlay(WSU,LBSU) and the down is 5.
runPlay begins executing and says "Oh, the down is 5, you turned it over on downs" and logs that. Changes possession, sets it to first down, yards to go = 10 (or goal in this case), sets the LBSU yardline to 93. Then, runPlay KEEPS EXECUTING.
So, now LBSU has the ball, but runPlay never exited. So it still thinks offense = WSU and defense = LBSU.
LBSU takes over with 2:48 from the 93 yard line and immediately throws a pick. Because runPlay thinks offense still = WSU, it reads WSU's QB as the offense to count the interception for. getEventPrefix doesn't care what you passed into runPlay, it just looks at gamePoss and it sees LBSU has the ball.
So, it says "LBSU 1st and Goal....WSU threw a pick"
qbInterception runs, changes possession back to WSU, runPlay exits and restarts.
The down is 1 so they don't turnover on downs. Everything else executes as normal. WSU decides to pass....and is picked off. Which is logged as it should be.
TL;DR: So what's the fix?
When I made turnover on downs, I just added an If statement to the top of runPlay. I should have put everything else in an else statement. Because I didn't, it ran turnover on downs, changed possession, and then kept running runPlay as if WSU was still the offense.
Oh and time never moved because qbInterception has no time decrease in it -- I'll add both in a quick fix
Ah ok, makes sense. You might also be able to just add a return;
statement if the down is >= 4 (meaning TO on downs) but I don't have the code in front of me (in class lol). But good catch either way!
Oh, you know a return probably would have been easier. I just stuck else { in front of the rest of the function and then an extra curly brace at the end.
Everything I found in stackoverflow was like "RABBLE RABBLE DON'T USE SO MANY RETURNS" so I wasn't sure if that's frowned upon or something, so I just did the else. I can change if you think that's better.
And yeah, when it happened I was in a very long very boring meeting at work, playing through a season, checked the log and was like "Wait....wtf", lol.
Yeah looks good! I'll close this issue.
I goofed something when I added turnover on downs. I suspect what happened is the pass was intercepted behind the line to gain or I forgot to check that the down is reset on a turnover so that two turnovers don't happen back to back.