Answers
Browse our full range of cheap rugs online at Land of Rugs. Huge choice of designs, colours & sizes. Free mainland UK delivery & Best Prices Online Guaranteed. Vagrant2.2.10; vagrant2.2.9; vagrant2.2.8; vagrant2.2.7; vagrant2.2.6; vagrant2.2.5; vagrant2.2.4; vagrant2.2.3; vagrant2.2.2; vagrant2.2.1; vagrant2.2.0.
- edited November 2013Answer ✓As you've noticed already, millis() returns how many milliseconds elapsed since program started:
http://processing.org/reference/millis_.htmlTo make a custom timer outta it, we just need to store apart current millis() in a variable when it starts.
Then,millis() - startTimer
returns how many milliseconds elapsed since timer had started rather than program! *-:) - edited November 2013thank you :)ok.I was thinking something like that.but.actually where should I place the startTimer var? This is the hierarchy of my code:the function 'end' (of every level) change a variable that allows the game to move to the next level. My idea was to put the timer function at the beginning of every level (before starting any part of it).I tried to put the startTimer variable in every place but cannot get it working.I tried to put it: inside the timer function, at the beginning of every level like this:I tried to put it in the draw, before every level but still nothing.actually I guess it is because processing call everything 60 fps and then keep refreshing the value of startTimer with millis().I'm a bit confused at this point :/ThanksP.
- Answer ✓Variables can be classified as field or local:
- Field-> its scope extends to whole
class
and remembers its value. - Local-> its scope is limited to the curly bracket's block it was declared in and forgets its stored value once gone.
Of course there are other categories too, like primitive/object & static/non-static.
But we'll leave those for another occasion! :DSo, if we want startTimer to survive w/ its stored value & be accessed everywhere, it gotta be declared as a field instead!
Just place its declaration at the top of the sketch, before setup() block preferably! - Field-> its scope extends to whole
- edited December 2013hi, thanks.I know about the global/local variables.but my point is.ok, I've already declared startTimer at the beginning, before setup, as global.but then, where am I supposed to update it?thnak youP.
- edited January 2014Answer ✓A basic idea is to have a constant to define how many milliseconds to w8.
Then check whether the diff. of current millis() - startTime > WAIT_CONSTANT;
If so, update startTimer w/ current millis() again! :D - edited December 2013ok.it's becoming quite difficult for me :D But how do I know what should be the correct value for WAIT_TIME?If I do this I see that the timer will restart every 3.5 second.but this is not what I need.or (more probably) I missed something.Ok, from the beginning, I need a countdown timer. a function. I pass a value to the function (10,5..) and that's the number of seconds where the countdown will begin. I need to call this function in different places inside the game (and I can't know at what time I'll have to call the function because every level of the game may take more or less time to finish).thanks for your patience :)
- edited October 2016Answer ✓For such flexible schedules, creating a custom AlarmTimer is needed.Nonetheless, Java comes w/ its own Timer class. And I've found a usage example of it below:
http://javarevisited.blogspot.com/2013/02/what-is-timer-and-timertask-in-java-example-tutorial.htmlAnd Java's reference too:
http://docs.oracle.com/javase/7/docs/api/java/util/Timer.htmlAnd here's what I've come up with: - edited December 2013Answer ✓
- edited December 2013First of all, thank you for your huge help.I think I understood (more or less) your code. A question: in the if statement.what does
& 0xF
mean? I would like to print out the countdown seconds (5,4,3,2,1), but now is too fast.thanksP. - edited January 2014Answer ✓B/c by default draw() is invoked @ 60 FPS, I've had to skip some
print('.');
. @-)
So, I decided to onlyprint('.');
once in 16 draw() calls!System variable frameCount keeps how many times draw() was called back.
Then,frameCount & 0xF
(0xF means 15) masks out all bits past least significant 4.
It's a bitwise operation and demands binary knowledge to figure out how it works though! :( Antivirus one pro 3 4 0 9.A non-bitwise format is:frameCount % 16 0
. :-'
Now, if you prefer 1 second countdown instead, that'd beframeCount % 60 0
. (*) - well.I knew &&.actually never used & :Dlast thing.I only need it to execute once. I'm trying to modify the value of hasFinished but I'm doing a mess.how can I make it execute only one time?thanksP.
- edited December 2013Answer ✓Actually, it only executes once already! 8-XWhat happens is that as soon the
if
block within draw() realizes that hasFinished becametrue
,
it re-invokes createScheduleTimer(), which in turn, re-schedule() the Timer w/ another TimerTask! :-BIt's just a simple demo on how Timer class works! You gotta implement that knowledge for your own custom needs!
Take notice that you can place anything you wanna happen after the wait time had passed into the run() block. - Yes exactly, I wanted to remove the hasFinished variable as I don't wan the timer to start again and again.now I set it to false and it's ok but I wanted to clear it up as I wont need it :)anyway thank you it's what I needed! (at the beginning I thought it was easier :D)P.
- Answer ✓You can get rid of that
boolean
completely! You just need to specify what you wanna happen once the time delay has passed! - well.I am so bad I can't delete it without having a non workling code :-' . btw this is what I ended up with, and it's exactly what I needed.thank you very much GoToLoop! :)
- Here is the link of good example of usage of Java Timer:->Timer
ProcessTimer_1.7.4[TNT]
Process Timer 1 7 4 Minecraft
ProcessTimer 1.7.4 | Mac OS X | 3.29 MB.
ProcessTimer shows the architecture, CPU utilization and the percentage of real memory used by the process that has focused on the GUI. By default, “follows” the process that has focused on the GUI, the most advanced application. The default behavior can be changed through the waiting process, and ProcessTimer follow the specific process for the rest of the life of the process, whether the front application has changed.
![Forge Forge](https://i.ebayimg.com/images/g/jaIAAOSwVmJe5LpI/s-l400.jpg)
Process Timer 1 7 4 Forge
![Processtimer 1 7 4 Processtimer 1 7 4](https://getsixtyfour.com/images/ProcessTimer-1.png)
Process Timer 1 7 4 Chord Progression
There are many features included in ProcessTimer well as CPU utilization reports. It also has formidable screen capture capabilities. You can take a screenshot of an application of five unique ways.
Features
– Open / activate an application
– Establish an application to open at login
– Open the preferences file (plist) of an application
– Display the information panel for an application Finder
– reveal the location of an application in Finder
– Capture a screenshot of an application of five unique ways
Features
– Open / activate an application
– Establish an application to open at login
– Open the preferences file (plist) of an application
– Display the information panel for an application Finder
– reveal the location of an application in Finder
– Capture a screenshot of an application of five unique ways