Page 1 of 1
Porting EQ2 bot - have question.
Posted: January 5th, 2005, 2:02 pm
by drakkiss
Is there anyway for WaitForLogFileText() to monitor a logfile in realtime while a seperate function is running?
So if 'xxxxx' appears in the logfile it will break out of the the running sub and enter a new one? Or is WaitForLogFileText() mainly useful in a DO loop where it checks the log each time the loop resets?
My problem is I need to be able to break out of these loops as soon as a 'xxxxx' is found in the logfile. Finishing up the loop or wasting seconds is not an option.
Also, let's say my logfile gets updated 37 times while my loop is finishing. Will WaitForLogFileText() check all 37 entries since it was last called?
Posted: January 5th, 2005, 2:10 pm
by wyvernx
Check out the XUFish for FFXI and WOW. They use a much better alternative using the FSO.
Posted: January 5th, 2005, 2:11 pm
by wyvernx
Actually, I tink asl18fs released a version 4 preview for his XUFish which uses nice classes. I beleive there is one for log entries.
Posted: January 5th, 2005, 2:12 pm
by drakkiss
wyvernx";p="52001 wrote:Actually, I tink asl18fs released a version 4 preview for his XUFish which uses nice classes. I beleive there is one for log entries.
Thanks, I'll check it out now. . .
Posted: January 5th, 2005, 2:23 pm
by drakkiss
EDIT - Found asl18fs' version.
Re: Porting EQ2 bot - have question.
Posted: January 7th, 2005, 8:49 am
by drakkiss
I have made a breakthrough! I found a wonderful FREE object called
COMScriptThread. It allows you to run functions and or entire scripts asynchronously! This is unbelievably useful for processing log files at high speed where you need to stop and start actions very quickly. You can download it
here.
It's use took me a couple hours to figure out as the documentation isn't stellar. But it's free so who cares! Below I am posting example code so you will not have to fight with it like I did.
Main code:
Code: Select all
'main.vbs
Option Explicit
Dim thread, XX, ThreadFile, sf
Set thread = CreateObject("newObjects.utilctls.COMScriptThread")
Set sf = CreateObject("newObjects.utilctls.SFMain") 'Like FSO but more flexible
Set ThreadFile = sf.OpenFile("test.vbs")
If thread.Start("VBScript",ThreadFile.ReadText(-2)) Then
If thread.Wait(30000) then 'Waiting up to 30 seconds - not necessarily required for this example
If thread.success Then 'The thread started!
thread.Execute("Tester") 'Execute the subroutine Tester from test.vbs
MsgBox("Success")
Else
thread.Stop
XX = thread.LastError 'Something went wrong waiting for the thread to start
MsgBox(XX) 'Let's see what it was
End If
Else
XX = thread.LastError 'The thread would not start at all if we got here.
MsgBox(XX) 'Let's see why?
End If
End If
Code we use to generate threads:
Code: Select all
'test.vbs
Option Explicit
Dim objFSO, objFSOText, objFolder, objFile
Dim strDirectory, strFile, strFile1
strDirectory = "c:\Scripts"
strFile = "\Special.txt"
strFile1 = "\Special1.txt"
Sub Tester
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
Echo "Just created " & strDirectory & strFile
End Sub
Sub Tester1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strDirectory & strFile1)
Echo "Just created " & strDirectory & strFile1
End Sub
It's a very simple example and I am not actually doing anything asynchronously, though I could be. I am simply demonstrating use of the members.
The Tester & Tester1 subroutines could be looped doing quite a bit of work if this script actually did anything useful. If that were the case, with this code I would have the power to start and stop either one at will.
One thing I have noticed is that there doesn't seem to be a way to stop routines that you have executing asynchronously in the same thread individually. You cannot stop someting you executed. Stop kills the entire thread. If you need that ability (as I do) just execute your subs using seperate threads (IE load the vbs file several times with a different thread name) or just split the subs that need that ability into different files (more effecient).
Posted: January 7th, 2005, 2:45 pm
by wyvernx
The biggest problem is you would not be able to use XU functions because scripts must be started with XU. So I suggest this. Send admin a pm with where ya found it. He can add it to the script host and you can then call xu script host functions to spawn a thread if you need one, and still use xu functinos in it.