Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Increasing timer problem

Author
Message
spikeyharold
12
Years of Service
User Offline
Joined: 26th Jan 2012
Location:
Posted: 26th Jan 2012 23:16
Hi.. This is a newbie question and Im sure its easily solved.. But ive been scratching my head for hours.
Basically I have a timer loop setup to keep track of the number of minutes passed during game time. However I want to introduce a time penalty and increase the time by a exponential amount every time a mistake is made.
My current timer loop is this :

The starttime is initialised at the beginning with starttime=Timer() and all is working well but I cant work out how to increase the time and for it to remain increased next loop without it re-increasing by the same amount. Any help would be greatly appreciated. Thanks
Millenium7
19
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 27th Jan 2012 04:01


increase/decrease the offset as necessary. It'll also allow you to show the (+30s) or whatever beside it
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Jan 2012 09:26
You could reduce startTime by the penalty.

Also, to make it more efficient, divide by 6000.0, rather than dividing by 60 and then by 1000. Make it 6000.0 rather than 6000, to make sure you get a float result, otherwise you'll only get full minutes. Your result field needs to be currentTime#

Millenium7
19
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 27th Jan 2012 10:08
Quote: "Also, to make it more efficient, divide by 6000.0, rather than dividing by 60 and then by 1000. Make it 6000.0 rather than 6000, to make sure you get a float result, otherwise you'll only get full minutes. Your result field needs to be currentTime#"


not to argue with this point (I agree with it) but it's been my experience that you'll never ever notice any difference in your game by optimising these sorts of things. Yes it will make a difference, but there are so many other areas that are worth tweaking and yield several thousand times more performance gain.

And so for the sake of readability I've never bothered to combine values, or shift division to multiplication. Even over 1,000 loops it's negligible
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Jan 2012 13:35 Edited at: 27th Jan 2012 13:36
Quote: " it's been my experience that you'll never ever notice any difference in your game by optimising these sorts of things"


in isolation, yes you're absolutely right. But if you get into the habit of good coding practises, it will make a difference to the completed application. As you compound your game performance with less-than-optimal practises you can reach the point where you no longer get the framerate you want, as seen all over these boards.

The alternative up above is 90% faster in my tests.

A good example of bad code compounded is this, and you see it a lot:




It would be far better as:


In a game running at 60FPS, the first example performs 119,999 unnecessary additional operations a second! Hence my stand on optimising code wherever possible.

Bulsatar
13
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 27th Jan 2012 17:31
Thanks for the code examples BatVink. Although I would never setup the first one, I have never considered how many operations have to be performed during a loop!
spikeyharold
12
Years of Service
User Offline
Joined: 26th Jan 2012
Location:
Posted: 27th Jan 2012 21:56
Thanks everyone. For some reason I got it in my head that adding the penalty to the currenttime within the loop would keep on increasing it every loop. Once that was firmly in my head I couldnt see a way out. "Couldnt see the wood for the trees"!
As for the optimization.. Ill try and optimise my code as i go. First time Ive touched programming since the ZX spectrum so Im a bit rusty!
Thanks Again
Millenium7
19
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 28th Jan 2012 06:22 Edited at: 28th Jan 2012 06:26
Quote: "in isolation, yes you're absolutely right. But if you get into the habit of good coding practises, it will make a difference to the completed application. As you compound your game performance with less-than-optimal practises you can reach the point where you no longer get the framerate you want, as seen all over these boards."


and just to throw another spanner into the works, you can also get into the loop of continually refining and improving your code. Keeping you stuck in one area when you should have many more features completed. Resulting in a lack of interest due to lack of progress, and abandoning your project. Been there many times

On the plus side my code is now very dynamic. I no longer write functions or routines with a singular purpose. I can throw curve balls at them and they'll continue to pump out accurate and expected results without recoding
My personal advice to the OP or anyone coding a reasonable size project is first to ensure your code does what it should at all times. Implement as many features as you can and ensure they are bug free and THEN optimise as necessary

Login to post a reply

Server time is: 2024-11-23 23:42:53
Your offset time is: 2024-11-23 23:42:53