Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Multiple Delay
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Twirlyman




PostPosted: Sun Jan 16, 2011 5:06 pm   Post subject: Multiple Delay

What is the problem you are having?
I have tried to reenact pacman with more simplicity by only making the pacman get points by getting the yellow circles that pop up in random locations BUT , since it's all in once loop i couldn't find out how to delay the pacmans movement sepretly than the circles that pop up, any suggestions? thanks.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Jan 16, 2011 5:20 pm   Post subject: RE:Multiple Delay

Time.Elapsed
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
doubleN




PostPosted: Sun Jan 16, 2011 8:06 pm   Post subject: Re: Multiple Delay

^Care to explain further? I'm having the same problem, only with people crossing the street and a car
Tony




PostPosted: Sun Jan 16, 2011 8:30 pm   Post subject: RE:Multiple Delay

Time.Elapsed can be used to keep track of the passage of time, without blocking. That is, if it's not time for thing one to happen yet, your program can go and work on thing two, and then check the time again later.

This contrasts against a blocking operation, such as Time.Delay, where your program will idle, and can't work on anything else.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
doubleN




PostPosted: Sun Jan 16, 2011 8:38 pm   Post subject: Re: Multiple Delay

So it's the same as the clock function, right?

Would it be something like this?
clock (t)
if t =4000 then
Draw person
move person
etc
end if

So what if I want the people to cross when there is a red light, and it occurs multiple times? Time.Elapsed only counts from where the process first began

Edit: Is this considered a thread hijacking?

Edit 2:

I think I get it.
More like this, right?
clock (initial)
loop
clock(current)
if clock (current) - (initial) = 5000 then
move whatever
end if
Tony




PostPosted: Sun Jan 16, 2011 9:04 pm   Post subject: RE:Multiple Delay

So far it sounds like the same question.

Yes, you've _almost_ got it.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
doubleN




PostPosted: Sun Jan 16, 2011 9:08 pm   Post subject: Re: Multiple Delay

Okay it's just

if current - initial mod 1000 = 0 then

Cause I want the guy to move every second
TerranceN




PostPosted: Sun Jan 16, 2011 9:23 pm   Post subject: RE:Multiple Delay

Unfortunately, while your program is doing other things, the elapsed time may go slightly past the second mark, making your check return false, even though a second has passed. A better way might be to check if there is a difference in the amount of seconds the game has run for, between the last frame and the current one.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Jan 16, 2011 9:34 pm   Post subject: RE:Multiple Delay

So reading documentation is awesome. Time.Elapsed
Quote:

The hardware resolution of duration is in units of 55 milliseconds. For example, Time.Elapsed may be off by as much as 55 milliseconds.

Oh, and that's assuming that this function call itself takes 0 time and you are doing nothing but checking the time.

That is, what TerranceN bluntly points out -- catching the exact 1 millisecond will likely not happen.

code:

if current - initial >= 1000
   % at least 1 second has passed


Though explaining why mod will not work with >= will be left as an exercise.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dragon20942




PostPosted: Tue Jan 18, 2011 7:48 pm   Post subject: RE:Multiple Delay

I don't know what Time.Elapsed is, and want to comment before reading. Can you use an if statement that checks if you can evenly divide Time.Elapsed? So if I wanted something to happen every 5 seconds, I can check if it divides evenly and use it for a trigger? Or does can Time.Elapsed be reset? I'd better read it first before I say anything else -_-'.
Tony




PostPosted: Tue Jan 18, 2011 8:01 pm   Post subject: RE:Multiple Delay

No, there will be a problem with that approach, and it's discussed above.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: