Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
A Delay function...
Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: A Delay function...

  1. #1

    A Delay function...

    the darkpallys ' subdelay function is very slow,i make my bot ' core and it are geting the 100% of cpu,i see a problem...
    i search on internet and found it,its is very fast,and my bot a low of my cpu...
    Code

    Code:
    Private Declare Sub Sleep Lib "Kernel32.dll" (ByVal dwMilliseconds As Long)
    Private Declare Function timeGetTime Lib "WinMM.dll" () As Long
    
    Public Sub Wait(ByVal inMilliseconds As Long)
        Dim SleepTime As Long, TimeNow As Long
        Dim SleepTo As Long, SleepEnd As Long
    
        Const MaxSleep As Long = 100
    
        TimeNow = timeGetTime()
        SleepTime = inMilliseconds \ 10
        If (SleepTime > MaxSleep) Then SleepTime = MaxSleep
        SleepTo = TimeNow + inMilliseconds
    
         Do
            DoEvents
            TimeNow = timeGetTime()
            SleepEnd = SleepTo - TimeNow
            If (SleepEnd <= SleepTime) Then Exit Do
            Call Sleep(SleepTime)
        Loop
    
        If (SleepEnd > 0) Then Call Sleep(SleepEnd)
    End Sub

  2. #2
    Administrator
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    1,274

    A Delay function...

    If you use the Sleep API it freezes the entire application. Using very small "Sleep's" wouldn't affect your program, however when you have multiple timers running calling the Sleep function, the effects would start appearing.

  3. #3

    A Delay function...

    then,what is the best delay function?

  4. #4
    Administrator
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    1,274

    A Delay function...

    I *think* that if you were to use multi threading you then could use the Sleep function as it would only put a certain thread to "sleep".. Hmm.. Honestly I don't have anything better than subDelay

  5. #5
    Senior Member
    Join Date
    Mar 2007
    Posts
    1,323

    A Delay function...

    Why would you want to sleep something? :O

  6. #6
    Administrator
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    1,274

    A Delay function...

    Quote Originally Posted by OsQu
    Why would you want to sleep something? :O
    Add a delay after the bot uses a potion or something o.O

    or to prevent lag-related problems

  7. #7

    A Delay function...

    i just want a delay...

  8. #8
    Senior Member
    Join Date
    Mar 2007
    Posts
    1,323

    A Delay function...

    In my experience all constant delays just make things worse. That was my biggest problem when developing a cavebot for TTB. Let's discuss about it as a good example:

    At first I thought it was a good idea so I went further. How it worked was that I had four states: walking, attacking, corpse opening and looting.. Because those things need to be at sync (cause of lag), I added few delays here and there to keep it at sync. Sounds good at first sight. However, what really happened was that no matter how I messed around with delays I couldn't get it at sync because my approach was wrong. Well, what I should've done in my humble opinion afterwards:

    I should've had event driven approach where the state was changed after certain action. For example with delay driven approach I had 500 ms pause after opening a corpse before I started looting. The correct approach should've to catch the packet from server which opens the backpack, and change the state there.

    What I'm trying to say, with good logic and a bit of planning you don't need any delays since you can do things in different, better way.

    Of course I'm always open for a conversation and I'd love to hear your experiences where delays were your golden saviour

  9. #9

    A Delay function...

    to long delays
    i guess that the best is to add one timer

  10. #10

    A Delay function...

    The best way is to use GetTickCount =p

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •