Computer Science Canada Getting a timer working |
Author: | Mustiko [ Sat Apr 19, 2008 2:16 pm ] | ||
Post subject: | Getting a timer working | ||
Hey everyone, I am having problems with getting this timer to work. I have a whack a mole program and want to make it so that the mole will disappear after a certain amount of time e.g. 1 second and I have tried many ways with time.elapsed but it either only works for the first mole or it flickers and finishes when u click or something its pretty messed up but I have a feeling that the problem si very obviously and I can't figure it out so if any of you could give me a hand then I would appreciate it thanks Oh by the way heres the code:
Thanks again ![]() |
Author: | syntax_error [ Sat Apr 19, 2008 3:58 pm ] |
Post subject: | RE:Getting a timer working |
If the time.elapsed is giving you trouble simply have a for looping counting seconds? then you can control the time when the for loop exits it will reach the not fast enough ? I think that would be the simplest way to get around using time.elapsed no? Anyone got better idea[s]? |
Author: | Nick [ Sat Apr 19, 2008 4:09 pm ] |
Post subject: | RE:Getting a timer working |
how about using Time.DelaySinceLast, forcing each loop run to be x milliseconds (example 10) then you want the mole to be there for 1 second (1 second = 1000 milliseconds) so 1000/10 loop runs until you make the mole dissapear |
Author: | Mustiko [ Sun Apr 20, 2008 2:28 pm ] |
Post subject: | Re: Getting a timer working |
ill try the for loop thing and for the Time.DelaySinceLast one where would I place that in the code? in the main loop or the loop inside the loop? |
Author: | LaZ3R [ Sun Apr 20, 2008 9:57 pm ] |
Post subject: | RE:Getting a timer working |
Really? None of you see his problem? The reason it only works for the first mole is because look at where you are giving st a value... OUTSIDE THE LOOP!!!!!! Every time a new mole appears, THAT'S when you set st:= Time.Elapsed |
Author: | Nick [ Sun Apr 20, 2008 10:27 pm ] |
Post subject: | RE:Getting a timer working |
I never look at code |
Author: | syntax_error [ Sun Apr 20, 2008 10:47 pm ] |
Post subject: | RE:Getting a timer working |
nor did I, takes too long. |
Author: | LaZ3R [ Mon Apr 21, 2008 10:02 pm ] |
Post subject: | RE:Getting a timer working |
Such a simple problem like his though usually results from a single error in the code. It took 2 seconds for me to spot so rather than making things more complicted for him, wouldn't it be easier to just glance at the code for a second? |
Author: | Mustiko [ Wed Apr 23, 2008 9:37 am ] |
Post subject: | Re: Getting a timer working |
Thank you laZ3R and I also found out that I stupidly forgot to declare that hit and nohit are false before the loop inside the loop. Thanks again and good job guyz! |