Jump to content
Sign in to follow this  

Need help with Readline, countline, and OR

Recommended Posts


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)

$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)

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?

Share this post

Link to post
Share on other sites

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 by Authenticity

Share this post

Link to post
Share on other sites

and I need it to read the last line.

FileReadLine($Location, -1)

then maybe you want to try StringInString($itemz, $Line-Read)



Share this post

Link to post
Share on other sites

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¢Ç¢{-³

work? (if i was looking for "[01:23:45] You damage the axe a little.")

EDIT: fixed last bit of code

Edited by lowpass

Share this post

Link to post
Share on other sites

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?\]')

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.