![]() |
Another easy one... Timer problem? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Another easy one... Timer problem? (/showthread.php?tid=3541) Pages:
1
2
|
Another easy one... Timer problem? - PhilOfPerth - 03-19-2025 Riddle me this, Batmen... easy for most, hard for me! When I run this bit of code, I expect Score to be 10,20,30... If I then delay beyond the 5 seconds allowed and enter N$ again, I expect the score to be 39 (which it is) But if I then enter N$ again (within the 5 seconds allowed), I get 50, instead of the 49 I expect. What am I doing wrong? Code: (Select All) Pick = 0 RE: Another easy one... Timer problem? - DSMan195276 - 03-19-2025 The issue is that `score` isn't cumulative, instead it's set equal to `Pick * 10 - TimePenalty` on each loop. `TimePenalty` is only the penalty for the current loop, it doesn't include any penalties for previous loops - even though there was a 1 point penalty on the previous loop to get 39 that penalty is lost when you do the next loop and `TimePenalty` is set to 0 (because you're within the 5 second window). A simple solution is to do `TimePenalty = TimePenalty + Int((T2 - T1) / 5)`, that way `TimePenalty` will include any penalties from previous loops. Alternatively you could stop using `Pick` and do `Score = Score + 10 - TimePenalty`, so that way score retains the penalties. Of course, don't do both of the options or you'll double-count the penalties ![]() RE: Another easy one... Timer problem? - PhilOfPerth - 03-19-2025 (03-19-2025, 06:05 AM)DSMan195276 Wrote: The issue is that `score` isn't cumulative, instead it's set equal to `Pick * 10 - TimePenalty` on each loop. `TimePenalty` is only the penalty for the current loop, it doesn't include any penalties for previous loops - even though there was a 1 point penalty on the previous loop to get 39 that penalty is lost when you do the next loop and `TimePenalty` is set to 0 (because you're within the 5 second window). Ahh, thanks DSMan. Another silly oversight on my part! Now I can continue with my new game. ![]() RE: Another easy one... Timer problem? - bplus - 03-19-2025 Quote:' penalty 5 points per second since last input Don't you want to multiply by 5, not divide by 5 for 5 point penalty for every second (delay of input) RE: Another easy one... Timer problem? - PhilOfPerth - 03-19-2025 (03-19-2025, 10:53 AM)bplus Wrote:Quote:' penalty 5 points per second since last input Hi bplus. No, I didn't want 5 points penalty per second, I wanted 1 point per 5 seconds. RE: Another easy one... Timer problem? - bplus - 03-19-2025 LOL how could I have read this wrong! Quote:' penalty 5 points per second since last input RE: Another easy one... Timer problem? - PhilOfPerth - 03-20-2025 (03-19-2025, 11:24 PM)bplus Wrote: LOL how could I have read this wrong! Oops, my bad (again)! Sorry! RE: Another easy one... Timer problem? - Pete - 03-20-2025 Okay, subtracting 5pts from Phil's rep as we speak... This will only take a second! Pete ![]() ![]() ![]() RE: Another easy one... Timer problem? - SMcNeill - 03-20-2025 Gosh, haven't you guys learned after all these years of coding: Comments can *say* anything. That doesn't mean the code actually *does* that, or is even supposed to do what the comments say. ![]() RE: Another easy one... Timer problem? - PhilOfPerth - 03-20-2025 (03-20-2025, 01:16 AM)Pete Wrote: Okay, subtracting 5pts from Phil's rep as we speak... This will only take a second! But I did that deliberately, so bplus et al would take notice! Honest! ![]() C'n I have my points back, pleeeeze Peter??? |