Posts: 799
Threads: 140
Joined: Apr 2022
Reputation:
33
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
GetInput:
T1 = Timer: ' start timer
Input N$
Pick = Pick + 1
T2 = Timer ' read timer again
TimePenalty = Int((T2 - T1) / 5) ' penalty 5 points per second since last input
Score = Pick * 10 - TimePenalty ' calculate score as Pick * 10 - TimePenalty
Print "Pick:"; Str$(Pick); " t1:"; Str$(T1); " t2:"; T2; " Timepenalty:"; TimePenalty; " Score:"; Score
GoTo GetInput
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/
Posts: 273
Threads: 2
Joined: Apr 2022
Reputation:
58
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
Posts: 799
Threads: 140
Joined: Apr 2022
Reputation:
33
(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).
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 
Ahh, thanks DSMan.
Another silly oversight on my part! Now I can continue with my new game.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/
Posts: 4,698
Threads: 222
Joined: Apr 2022
Reputation:
322
03-19-2025, 10:53 AM
(This post was last modified: 03-19-2025, 10:53 AM by bplus.)
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)
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 799
Threads: 140
Joined: Apr 2022
Reputation:
33
(03-19-2025, 10:53 AM)bplus Wrote: 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)
Hi bplus.
No, I didn't want 5 points penalty per second, I wanted 1 point per 5 seconds.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/
Posts: 4,698
Threads: 222
Joined: Apr 2022
Reputation:
322
LOL how could I have read this wrong!
Quote:' penalty 5 points per second since last input
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 799
Threads: 140
Joined: Apr 2022
Reputation:
33
03-20-2025, 12:24 AM
(This post was last modified: 03-20-2025, 12:26 AM by PhilOfPerth.)
(03-19-2025, 11:24 PM)bplus Wrote: LOL how could I have read this wrong!
Quote:' penalty 5 points per second since last input
Oops, my bad (again)! Sorry!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/
Posts: 2,910
Threads: 305
Joined: Apr 2022
Reputation:
167
Okay, subtracting 5pts from Phil's rep as we speak... This will only take a second!
Pete
Posts: 3,448
Threads: 376
Joined: Apr 2022
Reputation:
345
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.
Posts: 799
Threads: 140
Joined: Apr 2022
Reputation:
33
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/
|