jonesguy14 / footballcoach

Android App for playing/simulating/recruiting as a college football coach
Other
34 stars 8 forks source link

Turnovers on 4th Down Sometimes Creates Two Logs #33

Closed destilla closed 8 years ago

destilla commented 8 years ago

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.

screenshot_2016-03-23-11-46-49

destilla commented 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

jonesguy14 commented 8 years ago

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.

destilla commented 8 years ago

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.

destilla commented 8 years ago

Oh and time never moved because qbInterception has no time decrease in it -- I'll add both in a quick fix

jonesguy14 commented 8 years ago

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!

destilla commented 8 years ago

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.

jonesguy14 commented 8 years ago

Yeah looks good! I'll close this issue.