Lemures Posted December 23, 2003 Share Posted December 23, 2003 Is there any way to read the last line of a file that is constantly being written to? Ill just say it flat out: im trying to make a third party thing for Horizons. All its going to do is keep reading the log file, while Horizons always has open and is writing to, and have it play a sound when it says the "the resource you have been harvesting from has been depleted" message. This way i can be turned around watching tv or something, and i just listen for a beeping sound or something. I tried to have it wait until the selection is gone, but for some reason PixelSearch isnt working >< Link to comment Share on other sites More sharing options...
scriptkitty Posted December 23, 2003 Share Posted December 23, 2003 (edited) Sure, here is the example from help with notes: $x=0 $file = FileOpen("test.txt", 0) ; rename test.txt to your horizons filename ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ; I changed exitloop, to just a delay. Adjust acordingly, warning this is currently an endless loop now. ; you may wish to have a while in here as well $x=1 ; this found the first end, now you can use a if $x=1 and StringInStr($line,"harvesting from has been depleted",) type solution sleep(500) EndIf ; instead of this msgbox, put in an if statement that say plays a wave file if $line has your text ; currently it does nothing but read the lines. ; MsgBox(0, "Line read:", $line) Wend FileClose($file) If you need any more help, I don't mind stopping the drugery of certain game time sinks. I would put in a while winactive or something, or turn it on and off with autohotkey. You can also put in a count and an ini file so that it always starts at the end, or such before it starts. Ah what the heck, this will read to the end of the file, then check every half second to see if the text is in that line, and play the wave file if it is. Try it after adjusting the test.txt, and the sound file you want. $x=0 $file = FileOpen("c:\program files\horizons\test.txt", 0) ; rename test.txt to your horizons filename ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file) If @error = -1 Then $x=1 sleep(500) EndIf if $x=1 and StringInStr($line,"harvesting from has been depleted")>0 then SoundPlay("tada.wav") ;msgbox(1,$line,"Tada") ;put path in tada.wav, or place tada.wav in this directory. endif Wend FileClose($file) edit: oops had $file instead of $line Edited December 23, 2003 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
scriptkitty Posted December 23, 2003 Share Posted December 23, 2003 Also note that in my above example, the wait a half second is for autoit, if you write 20 lines in that half second, it will still check all of them in the next loop, and ring the tada.wav if it finds it. You could even run this from anouther computer with the horizon's directory shared, and thus turn up the sound only on that. You could also make one of these to check for other online friends saying hi or something. Never played Horizons, but it looks like it could be fun. ( nice to take out the tedius things. ) I added the $x check part so that if your log file was already 1000 lines long, it wouldn't ring the wave file for old info. AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
Lemures Posted December 24, 2003 Author Share Posted December 24, 2003 wow, thanks. i just skimmed what you wrote, but im going to spend the next half hour working with it making a few things... thank you!!! Im against macro's in games that give people an advantage over others. This sort of thing doesnt really give me an advantage i dont think... oh well. whatever. lol. thanks!! Link to comment Share on other sites More sharing options...
iceberg Posted May 31, 2008 Share Posted May 31, 2008 hi, scriptkitty mentioned that if you write 20 lines in that half second, it will still check all of them in the next loop. how do i make it such that it continues the search from the last EOF before the Sleep? thanks. mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 31, 2008 Moderators Share Posted May 31, 2008 (edited) This should keep track of all line changes... there's no logging.... just a simple concept:Global $nLastEOF = 0 Global $sTextFound = "" Global $nMonitorSleep = 500 Global $sFileLocationName = "File to track" While 1 $sTextFound = _FileMonitorLog($sFileLocationName, $nLastEOF) If $sTextFound <> "" Then MsgBox(64, "Last String Recorded", $sTextFound) Sleep($nMonitorSleep) WEnd Func _FileMonitorLog($sFile, ByRef $nLastEOF) Local $aSplit = StringSplit(StringStripCR(FileRead($sFile)), @LF) Local $sLog = "" If ($aSplit[0] > $nLastEOF) Then For $iCC = $nLastEOF + 1 To $aSplit[0] $sLog &= $aSplit[$iCC] & @CRLF Next $nLastEOF = $aSplit[0] EndIf Return $sLog EndFuncI wrote this in the quick reply box here... so there may be syntax mistakes... but the concept should be sound. Edit: I just noticed this topic is 5 years old!! Next time just start your own thread. Edited May 31, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
iceberg Posted June 1, 2008 Share Posted June 1, 2008 thank you very much SmOke_N! apologies for using a very old thread. just wanted to keep things relevant. mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now