by Spike » Sun Aug 17, 2014 5:28 am
when printing, add \n afterwards (second print?), or just use centerprint instead.
failure to do so will just weirdly bug out the prints.
secondly, your sprint_time value is presumably a global. this is stupid. if its a local then its even more broken.
this variable should be a field instead. self.sprint_time. this allows coop to work.
although, yes, if your game is strictly singleplayer then a global is fine - is your mod strictly single player? :s
either way, make sure its NOT a local! that might help explain how its always 0.
thirdly, counting frames is flawed. think functions are generally scheduled 10 times a second. that means your limit of 4 gives 0.4 (or so, it can actually vary a little) seconds of sprinting... which isn't much at all.
if instead your concept of frames is that of playerprethink/playerpostthink, then you're getting noticably more frames than that (72 or so, but can vary)! counting frames is just unreliable however you look at it.
the solution is to add/subtract frametime and work purely in actual time, rather than in frames.
yes, this means that you can somewhat easily over-spend. just make sure the player still has to pay (in downtime) and your half-frame overspend is unlikely to be a problem.
.