Delay

This is a discussion on Delay within the C++ Programming forums, part of the General Programming Boards category; I'm trying to create a delay in my program so you can see when a character is being moved accross ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    6

    Delay

    I'm trying to create a delay in my program so you can see when a character is being moved accross the screen.

    I know it's a for loop and I believe it goes something like this.


    int delay;
    for (delay; delay<10000000;delay--)

    am I right???
    I'm sure there are changes.

    THanx for your help

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> for (delay; delay<10000000;delay--)


    for (delay = 0; delay<1000000; delay++);

    That's a way to delay, not a good one because your process is hogging the cpu the whole time, but without more details, I won't suggest an alternative.

    You set delay initially to zero, and as long as delay is less than the value you have entered, you increment delay.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Unregistered
    Guest
    I have read your post, and i am struggling with the same problem.
    i used this way to delay for some time, when I was only programming in QB (For i=1 to 1000:next i)
    It is the simplest way to delay, but it has a major setback:
    It is CPU dependent (i.e,on a pentium the dlay is shorter than on, for example, a 386)
    If you now know any better way(in C/C++, please let me know!
    you can mail to jonasw88@hotmail.com , so i can put it on my site ( <url>http://go.to/jtechcpp</url> )

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    if using dos (real dos) then #include <dos.h> and in there is a function called sleep(x) where x is seconds to delay i think.

    if using win32 console then #include<windows.h> and in there is a function called Sleep(x) where x is milliseconds to delay.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    The reason I didn't suggest this is lack of details of course. It might also be delay() or Delay() or wait() or Wait() ... !
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Regarding delay in the connection
    By byatin in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-19-2008, 03:59 PM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 08:26 PM
  3. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 12:23 PM
  4. Put A Delay To A Buffer
    By timmer in forum C Programming
    Replies: 2
    Last Post: 05-24-2005, 10:45 AM
  5. 2-3 Second delay with alarm()
    By Longie in forum C Programming
    Replies: 11
    Last Post: 06-20-2004, 09:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21