Jump to content

Parsing Question


 Share

Recommended Posts

Im reading a line of text from a chat log. The last word in the line I want to execute will always be the same but the rest of the line will have variable words.I want the script to look at the last word in the line. How could I get the script to look at just the last word of a line. For example:

[11/30/07 15:55:56] You hit Sand Beetle for 33 slash damage.

[11/30/07 15:55:57] Sand Beetle missed you.

[11/30/07 15:55:58] Sand Beetle missed you with Mandible Crush I.

[11/30/07 15:55:59] Gained Warrior experience: 108

[11/30/07 15:55:59] You hit Sand Beetle for 32 slash damage.

[11/30/07 15:55:59] Sand Beetle has been killed.

In the last line the object being killed will vary but the word killed will always be the same so I need to search for "killed". I have my script now checking the last line of the log but for "Sand Beetle has been killed." and then execute another func on seeing that. That limits me to what I can fight or either have to constantly change the search phrase.

Link to comment
Share on other sites

Use StringSplit() using a space " " as a separator. The position of the last element will be given by the [0] element of the array returned by StringSplit.

Example:

$MyString=StringSplit("This is my string"," ")
MsgBox(0,"","The last word is " & $MyString[$MyString[0]])
Link to comment
Share on other sites

Ok I have ran into another problem.

Do

$file = FileOpen($source, 0)

$CountLines = _FileCountLines($source)

$line = FileReadLine($source, $CountLines)

$MyString=StringSplit($line," ")

FileClose($source)

Sleep(500)

Until $MyString[$MyString[0]] = "killed."

This seems not to close the file and I get an error that Ive exceeded the max number of open files. I am opening the file. Finding the number of lines of the file. Reading the last line. Checking the last word in the line and setting it to a var. Then closing the file. Repeat until $MyString="killed." Correct?

Link to comment
Share on other sites

Do
    $file = FileOpen($source, 0)
    $CountLines = _FileCountLines($file)
    $line = FileReadLine($file, $CountLines)
    $MyString = StringSplit($line, " ")
    FileClose($file)
    Sleep(500)
Until $MyString[$MyString[0]] = "killed."
Link to comment
Share on other sites

Why not open the file BEFORE entering the loop and closing it AFTER the loop?

open

LOOP

close

My guess is the file will be written constantly and he has to keep it up to date. Actually FileOpen and Close is not required if the filename is given.
Link to comment
Share on other sites

Well he was obiously opening, reading and closing the files wrong (you were using the path not the file handle returned by FileOpen). I was just saying that it should be better opening the file first, reading it in a loop and then close it. It's pointless to do it the way he does, he could just use FileRead(path)

Link to comment
Share on other sites

Well he was obiously opening, reading and closing the files wrong (you were using the path not the file handle returned by FileOpen). I was just saying that it should be better opening the file first, reading it in a loop and then close it. It's pointless to do it the way he does, he could just use FileRead(path)

Probably, saved two lines.
Link to comment
Share on other sites

Yes the file will be constantly written to. Also the file name will change everytime the game is closed. Filename is like.. client_chat_log_12-01-07_10_05_42...date and time is stamped when the game opens and creates the chat log. Ive tried the code above but for some reason it isnt reading the file. I can use this code and I get no return.

#include <file.au3>

$path = "C:\Program Files\Virtrium\Horizons\logs\"

$log = InputBox("File Name", "C&P File Into Box", "", "")

$source = $path & $log & ".txt"

$file = FileOpen($source, 0)

$CountLines = _FileCountLines($file)

$line = FileReadLine($file, $CountLines)

$MyString = StringSplit($line, " ")

FileClose($file)

Sleep(500)

MsgBox(64,"Title", $MyString)

Im sure theres a better way to get the file but Im not there yet with the knowledge of au3.

Edited by jimmyjoe
Link to comment
Share on other sites

Yes the file will be constantly written to. Also the file name will change everytime the game is closed. Filename is like.. client_chat_log_12-01-07_10_05_42...date and time is stamped when the game opens and creates the chat log. Ive tried the code above but for some reason it isnt reading the file. I can use this code and I get no return.

#include <file.au3>

$path = "C:\Program Files\Virtrium\Horizons\logs\"

$log = InputBox("File Name", "C&P File Into Box", "", "")

$source = $path & $log & ".txt"

$file = FileOpen($source, 0)

$CountLines = _FileCountLines($file)

$line = FileReadLine($file, $CountLines)

$MyString = StringSplit($line, " ")

FileClose($file)

Sleep(500)

MsgBox(64,"Title", $MyString)

Im sure theres a better way to get the file but Im not there yet with the knowledge of au3.

Read your last line of code carefully, it's an array :)
Link to comment
Share on other sites

Ok I got it and understand about that last line array thing now. I just assumed I need to open and close the file. Just did this and works great now.

Do

$CountLines = _FileCountLines($source)

$line = FileReadLine($source, $CountLines)

$MyString=StringSplit($line," ")

Sleep(500)

Until $MyString[$MyString[0]] = "killed."

Thx for the info and help.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...