Computer Science Canada Time.Elapsed at x time +5000.. |
Author: | Geostigma [ Sat May 05, 2007 9:07 am ] | ||||
Post subject: | Time.Elapsed at x time +5000.. | ||||
I'm having issues trying to get my time elapse to work properly. I know that time elapse calculates the time the program starts until the program ends. Well how do I get my Time.Elapse do something like. If I hit a certain object at any time then after 5 seconds go by then it does what I want. I seriously can't get it to work. I saw another thread but it doesn't seem to answer my question I tried a few renditions of
or
|
Author: | Cervantes [ Sat May 05, 2007 1:11 pm ] | ||||
Post subject: | RE:Time.Elapsed at x time +5000.. | ||||
This should be a syntax error in Turing, I think, since Turing doesn't really like to use expressions, but rather statements. You should use = for comparison. := is for assignment. try something like this:
|
Author: | Geostigma [ Sat May 05, 2007 9:20 pm ] |
Post subject: | RE:Time.Elapsed at x time +5000.. |
Yeah sorry I wrote that on the top of my head I didn't copy it from Turing because I left my file on my Flash Drive. Ill take a look and try what you posted. Any errors in my code syntax wise is totally due to the lack of having the file on me lol. |
Author: | Geostigma [ Sun May 06, 2007 10:01 pm ] | ||
Post subject: | RE:Time.Elapsed at x time +5000.. | ||
still not working.
ghost just permanently freezes |
Author: | Cervantes [ Sun May 06, 2007 10:50 pm ] |
Post subject: | RE:Time.Elapsed at x time +5000.. |
No, that wouldn't work. Do you know why? It's because you set timer := Time.Elapsed, then on the next line (which happens almost instantly, so 0 milliseconds have passed) you're asking if timer >= Time.Elapsed + 5000. Well, of course it won't be, because timer = Time.Elapsed. So that's asking if Time.Elapsed >= Time.Elapsed + 5000, which is essentially asking if 0 >= 5000. Certainly not. |
Author: | Geostigma [ Mon May 07, 2007 11:26 am ] | ||
Post subject: | Re: Time.Elapsed at x time +5000.. | ||
Well I don't know why your getting all pissed off when your method doesn't work either. I did both the one i just posed and copied and pasted your code and subbed what I needed to be done after 5 seconds. Mine makes the object stand still. Yours makes the object continue on.
|
Author: | program_x [ Mon May 07, 2007 1:11 pm ] | ||
Post subject: | Re: Time.Elapsed at x time +5000.. | ||
what if you had something like two vars, one for the first time, and one to compare angainst like:
i din't really look at your code, but it sounds like an issue involving how long until to execute somthing help this helps note to clayton: i added code tags already |
Author: | program_x [ Mon May 07, 2007 1:15 pm ] |
Post subject: | Re: Time.Elapsed at x time +5000.. |
sorry, i ment to say "hope this helps" |
Author: | Geostigma [ Mon May 07, 2007 2:12 pm ] |
Post subject: | RE:Time.Elapsed at x time +5000.. |
Yeah i tried that one at the bigging and also again just now. I don't know whats wrong with this. |
Author: | Cervantes [ Mon May 07, 2007 6:03 pm ] | ||
Post subject: | Re: Time.Elapsed at x time +5000.. | ||
Geostigma @ Mon May 07, 2007 11:26 am wrote: Well I don't know why your getting all pissed off when your method doesn't work either.
I was not getting pissed off. I'm sorry if that's how I came across. I was actually rather mellow when I wrote that. The fact that I did not offer a solution in that post does not mean I was getting frustrated with you. I was merely trying to get you to think about what's going on. We learn best by thinking ourselves, not by being told the answers. However, you are correct. I made a mistake in my code. I meant to give this:
I think that should work. program_x: introducing a second variable, time2, does nothing for us. See, you assigned time2 to be Time.Elapsed, and then in the very next line used time2. We could have just used Time.Elapsed there. Also, you used = for comparison. This is risky. Because we are working with time, if our main loop is big and honking, it might take, say, 4 milliseconds to execute once. Then there is a 1 in 4 chance that the equality will be true. 3/4 of the time, time2-time1 will skip right over the number 5000: it might be 4993, then 4997, then 5001, then 5005, ... and we never entered the if statement that we wanted to. Using >= avoids this problem, but you probably have to introduce a second variable (boolean, in this case) as I did in my code. |
Author: | Geostigma [ Mon May 07, 2007 9:39 pm ] | ||
Post subject: | RE:Time.Elapsed at x time +5000.. | ||
Yeah that doesn't work either lol. I added your set your do_delayed_event to false after it because I noticed that you never had it before hand. I'm not just using answers I'm trying to play with it. if you want I can PM my whole file to you because I rather not give it out to the public. Its not hush hush I just don't want some people stealing certain procedures in it. EDIT: okay wtf... Now if I run over the space where the object sits idle.. it starts up again when I have just the timer set to delay. Hokay... wtf... and this is before I added the true statement. I dont know if telling you its in a procedure changes anything
|
Author: | splik [ Sun May 13, 2007 6:45 pm ] |
Post subject: | RE:Time.Elapsed at x time +5000.. |
try this var timer : int := 0 var g1state_just_became_2 : boolean := true if g1state_just_became_2 = true then g1state_just_became_2 := false timer := Time.Elapsed end if if Time.Elapsed - 5000 >= timer then g1state := 1 end if |