lowpass Posted April 20, 2009 Posted April 20, 2009 I am writing a script that opens up a file that is being constantly wrote to, and I need it to read the last line. However, when the countline runs the first time, it reads the line of text when it was opened last - could be 2 days old, could be 5 seconds. I came up with the fix to just do two countlines, so it finds the most recent line and outputs it. Is there a solution to this? Or is this the best way to get this done? Example of what that means (I am very bad at wording things) $CountLines = _FileCountLines("C:\Users\....") gives an output of line 23 where as _FileCountLines("C:\Users\....") output of line 23 $CountLines = _FileCountLines("C:\Users\....") output of line 400 Also, using the line given from above, i use readline to...read it, and it gives something out. Now, I am using a script that compares that line to a HUGE list of possible things, but I have not found a way to make this work. Example - $itemz = "boot" OR "coif" OR "sword" OR "axe" OR "shard" ... goes on for 100 things. $impc = pixelsearch ( $tlx, $tly, $brx, $bry, $water, 0, 2) _FileCountLines("C:\Users\....") $CountLines = _FileCountLines("C:\Users\....") $text = filereadline ("C:\Users\....", $countlines) While $1 = 1 ... if $text = "You damage the "& $itemz & " a little." then Mouseclick ("right", $impc[0], $impc[1], 1) repair() EndIf ... wend So, if $text gave an output of "You damage the axe a little." , the script will work if $itemz = "axe", but if I include an OR in there, the function breaks; the script ends. Is there anyway to make $itemz include an OR func or something of the sort? I really do not want to have it do something like ... if $text = "You damage the axe a little." then ... else if $text = "You damage the coif a little." then ... else if $text = .... I understand that is fully possible, but it would seriously slow the script down?
Authenticity Posted April 20, 2009 Posted April 20, 2009 (edited) Use StringRegExp like:Dim $sItems = '(?:axe|knife|hammer|soap)' If StringRegExp($sLine, '(?i)You damage the ' & $sItems & ' a littile.') Then...Edit: damage...Edit2: Changed to non capturing instead of character class.... Edited April 20, 2009 by Authenticity
Valuater Posted April 20, 2009 Posted April 20, 2009 and I need it to read the last line.FileReadLine($Location, -1)then maybe you want to try StringInString($itemz, $Line-Read)8)
lowpass Posted April 21, 2009 Author Posted April 21, 2009 (edited) Thank you! That fixed that, but now I realized I have another problem. Me just now being introduced to Dim and stringregexp, I am not sure how to do this. I need to make a thing to look for a timestamp - the time stamp can look like [12:34:45] but being time, it can change #'s (wow, I am good at describing the anomalies of life)... I think it would look like this - dim $hour1 = '(0|1|2)' dim $hour2 = '(0|1|2)' dim $min1 = '(0|1|2|3|4|5|6)' dim $min2 = '(0|1|2|3|4|5|6|7|8|9) ; $min1 and $min2 are usable for secondsoÝ÷ Úë"a¢Ç¢{-³ .Ö®¶sbb7G&æu&VDWÒb33c·FWBÂgV÷Cµ²gV÷C²fײb33c¶÷W#fײb33c¶÷W#"fײgV÷C³¢gV÷C²fײb33c¶Öãfײb33c¶Öã"fײgV÷C³¢gV÷C²fײb33c¶Öãfײb33c¶ÖâfײgV÷CµÒ÷RFÖvRFRgV÷C²fײb33c¶FV×¢fײgV÷C²ÆGFÆRâgV÷C° work? (if i was looking for "[01:23:45] You damage the axe a little.") EDIT: fixed last bit of code Edited April 21, 2009 by lowpass
Authenticity Posted April 21, 2009 Posted April 21, 2009 If you need to match a square brackets you need to escape it like '\[' because otherwise it may be interpreted as a character class. For the timestamp (if you can call it a timestamp) you don't need something special, just do something like: Dim $aMatch = StringRegExp($text, '\[\d\d?:\d\d?:\d\d?\]')
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