d0n Posted July 20, 2009 Share Posted July 20, 2009 Hello, i am stuck again not sure why this time again lol Here is the code, and the files i try to parse is below, the code doesn't work with the 2nd set of lines. It resets the count to the very last line instead of adding to it #Include <File.au3> $Log = @ScriptDir&"\Logger.ini" If FileExists(@ScriptDir&"\Logger.ini") = 0 Then _FileCreate(@ScriptDir&"\Logger.ini") IniWrite($Log, "Name", "####", "0") EndIf Dim $sStr = FileRead(@scriptdir & "\test.txt") Dim $sPatt = '(?i)\[[^]]*\]\s*(.*?)(?:hit|punche?|slashe?)s?.*?for\s*(\d+)' Dim $aLines = StringSplit($sStr, @CRLF, 1) Global $P1_Total = 0 For $i = 1 To $aLines[0] Local $aMatch = StringRegExp($aLines[$i], $sPatt, 1) If UBound($aMatch) = 2 Then $a = IniReadSection($Log, "Name") IniDelete($Log, "Name", "####") $aMatch[0] = StringTrimRight($aMatch[0],1) For $size=1 To $a[0][0] If $a[$size][0] = $aMatch[0] Then $dmg = IniRead($Log, "Name", $aMatch[0], "0") $dmg = $dmg + $aMatch[1] IniWrite($Log, "Name", $aMatch[0], $dmg) Else IniWrite($Log, "Name", $aMatch[0], $aMatch[1]) EndIf Next EndIf Next This works with the code [1:41:21 PM Jun 04 2009] You slash A Dragon for 10 points of damage. [1:41:21 PM Jun 04 2009] You slash A Dragon for 10 points of damage. [1:41:24 PM Jun 04 2009] A Dragon hits you for 70 points of damage. This doesn't work with the code [1:41:21 PM Jun 04 2009] You slash A Dragon for 10 points of damage. [1:41:24 PM Jun 04 2009] A Dragon hits you for 70 points of damage. [1:41:21 PM Jun 04 2009] You slash A Dragon for 10 points of damage. Link to comment Share on other sites More sharing options...
MDCT Posted July 20, 2009 Share Posted July 20, 2009 the code doesn't work with the 2nd set of lines. It resets the count to the very last line instead of adding to it Which code do you mean? It seems to get all the lines. Add this: ConsoleWrite( "First text: " & $a[$size][0] & @CRLF & "Second text: " & $aMatch[0] & @CRLF & @CRLF) After If $a[$size][0] = $aMatch[0] Then. It shows all three lines with both test.txt. Link to comment Share on other sites More sharing options...
d0n Posted July 20, 2009 Author Share Posted July 20, 2009 Returns this with 1st set of test.txt, which works because it added up correctly [Name] You=20 A Dragon=70 returns this with the 2nd set of test.txt, which is not working because it still should say You=20 [Name] You=10 A Dragon=70 Link to comment Share on other sites More sharing options...
MDCT Posted July 20, 2009 Share Posted July 20, 2009 Is this what you want? If UBound($aMatch) = 2 Then $a = IniReadSection($Log, "Name") IniDelete($Log, "Name", "####") $aMatch[0] = StringTrimRight($aMatch[0],1) For $size=1 To $a[0][0] If $a[$size][0] = $aMatch[0] Then $dmg = IniRead($Log, "Name", $aMatch[0], "0") $dmg = $dmg + $aMatch[1] IniWrite($Log, "Name", $aMatch[0], $dmg) exitloop EndIf Next If $size > $a[0][0] then IniWrite($Log, "Name", $aMatch[0], $aMatch[1]) EndIf The problem was the else. It is still in the loop so the script will write double each time. So I set it to exit the loop and check if the loop found a match or not. Link to comment Share on other sites More sharing options...
d0n Posted July 20, 2009 Author Share Posted July 20, 2009 mm, ok thanks i think i get it now 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