Jump to content

Read File line(3 Parts to each line)


Recommended Posts

Hey everybody, Loving the new fourms By the way!

Im to read a Text file with lines like this:

<WP> <X: 1886.24975585938 > <Y 1609.73742675781> <Z 92.4534606933594>

Each line needs to be diffrent, If i get the same line more than once in a row, it needs to delete.

Here is my script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <NomadMemory.au3>

HotKeySet("{F11}", "_Move")
;settings -----------------
$Playerbase = 0x010BD5F4
$Off1=0x34
$Off2=0x24
$Playerrotation = 0x7A8
$CLicktomove = 0x11180A0
$Movex = 0x8C
$MoveY = 0x90
$MoveZ = 0x94



Func _Move()
$filetoread = FileOpenDialog("Please choose the profile", @ScriptDir, ".txt")
$i = 0
While 1
    ;Not sure what to do here
    $i + 1
    FileReadLine($filetoread, $i)

        _MemoryWrite($CLicktomove + 0x8C, $wowprocess, <X HERE>, 'float')
        _MemoryWrite($CLicktomove + 0x90, $wowprocess, <Y HERE>, 'float')
        _MemoryWrite($CLicktomove + 0x94, $wowprocess, <Z HERE>, 'float')
        _MemoryWrite($CLicktomove + 0x1C, $wowprocess, 4, 'int')

WEnd
EndFunc

How can i make my script read the X, Y & Z from the text file, but read the next line everytime.

I have already made the script to make the text file.

Can anybody help.

Link to comment
Share on other sites

Your best bet would be to use stringregexp on the line read from the file. You'll probably have to tweak this exp​ression depending on if the lines follow that exact format, but this should get you started.

StringRegExp(FileReadLine($filetoread, $i),(?<Z><Z.*[\d\.]*.*>), 3)
 StringRegExp(FileReadLine($filetoread, $i), (?<X><X.*[\d\.]*.*>), 3)
 StringRegExp(FileReadLine($filetoread, $i), (?<Y><Y.*[\d\.]*.*>), 3)

If you haven't learned stringregexp yet, Expresso is a great tool.

Edited by dantay9
Link to comment
Share on other sites

Ok thanks for that.

Here is my code

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <NomadMemory.au3>

HotKeySet("{F11}", "_Move")
HotKeySet("{F10}", "_ReadWP")

SETPRIVILEGE("SeDebugPrivilege", 1)
Dim $ProPID = WinGetProcess("World of Warcraft")
$wowprocess = _MemoryOpen($ProPID)

Global $filetoread

;settings -----------------
$Playerbase = 0x010BD5F4
$Off1=0x34
$Off2=0x24
$Playerrotation = 0x7A8
$CLicktomove = 0x11180A0
$Movex = 0x8C
$MoveY = 0x90
$MoveZ = 0x94
while 1

WEnd



Func _Move()
$filetoread = FileOpenDialog("Please choose the profile", @ScriptDir, ".txt")
$i = 0
While 1
    ;Not sure what to do here
    $i =+ 1
    FileReadLine($filetoread, $i)

        ;_MemoryWrite($CLicktomove + 0x8C, $wowprocess, <X HERE>, 'float')
        ;_MemoryWrite($CLicktomove + 0x90, $wowprocess, <Y HERE>, 'float')
        ;_MemoryWrite($CLicktomove + 0x94, $wowprocess, <Z HERE>, 'float')
        ;_MemoryWrite($CLicktomove + 0x1C, $wowprocess, 4, 'int')

WEnd
EndFunc



Func _readWP()
    $filetoread = "Test Profile.txt"
$i = 0
While 1
    $i=+ 1
    $checkforend = FileReadLine($filetoread, $i)
    If $checkforend = "<WP> <End of waypoints>" Then
        ExitLoop
    EndIf
$msb1 = StringRegExp(FileReadLine($filetoread, $i), ("<X><X.*[\d\.]*.*>"), 3)
$msb2 = StringRegExp(FileReadLine($filetoread, $i), ("<Y><Y.*[\d\.]*.*>"), 3)
$msb3 = StringRegExp(FileReadLine($filetoread, $i), ("<Z><Z.*[\d\.]*.*>"), 3)


MsgBox(64, "testx", $msb1)
MsgBox(64, "testy", $msb2)
MsgBox(64, "testz", $msb3)
WEnd
EndFunc

I'm not sure what to do now tho.

Here is a full text file, that it will b reading from:

<WP> <X: 1886.24975585938 > <Y 1609.73742675781> <Z 92.4534606933594>
<WP> <X: 1886.24975585938 > <Y 1609.73742675781> <Z 92.4534606933594>
<WP> <X: 1886.24975585938 > <Y 1609.73742675781> <Z 92.4534606933594>
<WP> <X: 1886.24975585938 > <Y 1609.73742675781> <Z 92.4534606933594>
<WP> <X: 1884.64575195313 > <Y 1608.453125> <Z 92.4053115844727>
<WP> <X: 1882.12329101563 > <Y 1604.54064941406> <Z 92.2791137695313>
<WP> <X: 1880.98168945313 > <Y 1602.76989746094> <Z 92.2904891967773>
<WP> <X: 1879.27099609375 > <Y 1600.11657714844> <Z 92.2510375976563>
<WP> <X: 1877.53063964844 > <Y 1597.474609375> <Z 91.9838562011719>
<WP> <X: 1875.21691894531 > <Y 1594.99096679688> <Z 91.6089324951172>
<WP> <X: 1872.55578613281 > <Y 1593.10522460938> <Z 91.3740539550781>
<WP> <X: 1868.9775390625 > <Y 1590.64916992188> <Z 91.4595031738281>
<WP> <X: 1866.25915527344 > <Y 1588.78344726563> <Z 91.7644805908203>
<WP> <X: 1863.52392578125 > <Y 1586.83569335938> <Z 92.0773239135742>
<WP> <X: 1861.599609375 > <Y 1583.75524902344> <Z 92.5257339477539>
<WP> <X: 1860.50622558594 > <Y 1580.04504394531> <Z 93.6301803588867>
<WP> <X: 1860.36254882813 > <Y 1577.25256347656> <Z 94.3138275146484>
<WP> <X: 1860.51025390625 > <Y 1573.15319824219> <Z 94.3138275146484>
<WP> <X: 1860.64489746094 > <Y 1569.41760253906> <Z 94.3138275146484>
<WP> <X: 1860.78662109375 > <Y 1565.48620605469> <Z 94.3138275146484>
<WP> <X: 1860.90405273438 > <Y 1562.22631835938> <Z 94.3028717041016>
<WP> <End of waypoints>

When i run the above code all i get is a message box with the number 1 in it.

Also it needs to stop when it sees "<WP> <End of waypoints>"

Please help

Edited by Rorka
Link to comment
Share on other sites

Hi xD.. this is what I came up with.. I re-wrote this function..

Func _readWP()
    $filetoread = "Test Profile.txt"
$i = 0
While 1
    $i=+ 1
    $checkforend = FileReadLine($filetoread, $i)
    If $checkforend = "<WP> <End of waypoints>" Then
        ExitLoop
    EndIf
$msb1 = StringRegExp(FileReadLine($filetoread, $i), ("<X><X.*[\d\.]*.*>"), 3)
$msb2 = StringRegExp(FileReadLine($filetoread, $i), ("<Y><Y.*[\d\.]*.*>"), 3)
$msb3 = StringRegExp(FileReadLine($filetoread, $i), ("<Z><Z.*[\d\.]*.*>"), 3)


MsgBox(64, "testx", $msb1)
MsgBox(64, "testy", $msb2)
MsgBox(64, "testz", $msb3)
WEnd
EndFunc

To this..

Func _readWP()
    $filetoread = "Test Profile.txt"
$i = 0
While 1
    $i=+ 1
    $checkforend = FileReadLine($filetoread, $i)
    If $checkforend = "<WP> <End of waypoints>" Then
        ExitLoop
    EndIf
$msb = _Extract (FileReadLine ($filetoread, $i))

MsgBox(64, "testx", $msb['1'])
MsgBox(64, "testy", $msb['2'])
MsgBox(64, "testz", $msb['3'])
WEnd
EndFunc

Func _Extract ($iLine)
Local $iSplit, $iReturn
$iSplit = StringSplit (StringTrimLeft ($Data, '5'), '> <')
Dim $iReturn['4']
$iReturn['1'] = $iSplit['3'] 
$iReturn['2'] = $iSplit['8']
$iReturn['3'] = $iSplit['12']
Return $iReturn
EndFunc

Hope this helps :) !

- John

Latest Projects :- New & Improved TCP Chat

Link to comment
Share on other sites

Hi xD.. this is what I came up with.. I re-wrote this function..

Func _readWP()
    $filetoread = "Test Profile.txt"
$i = 0
While 1
    $i=+ 1
    $checkforend = FileReadLine($filetoread, $i)
    If $checkforend = "<WP> <End of waypoints>" Then
        ExitLoop
    EndIf
$msb1 = StringRegExp(FileReadLine($filetoread, $i), ("<X><X.*[\d\.]*.*>"), 3)
$msb2 = StringRegExp(FileReadLine($filetoread, $i), ("<Y><Y.*[\d\.]*.*>"), 3)
$msb3 = StringRegExp(FileReadLine($filetoread, $i), ("<Z><Z.*[\d\.]*.*>"), 3)


MsgBox(64, "testx", $msb1)
MsgBox(64, "testy", $msb2)
MsgBox(64, "testz", $msb3)
WEnd
EndFunc

To this..

Func _readWP()
    $filetoread = "Test Profile.txt"
$i = 0
While 1
    $i=+ 1
    $checkforend = FileReadLine($filetoread, $i)
    If $checkforend = "<WP> <End of waypoints>" Then
        ExitLoop
    EndIf
$msb = _Extract (FileReadLine ($filetoread, $i))

MsgBox(64, "testx", $msb['1'])
MsgBox(64, "testy", $msb['2'])
MsgBox(64, "testz", $msb['3'])
WEnd
EndFunc

Func _Extract ($iLine)
Local $iSplit, $iReturn
$iSplit = StringSplit (StringTrimLeft ($Data, '5'), '> <')
Dim $iReturn['4']
$iReturn['1'] = $iSplit['3'] 
$iReturn['2'] = $iSplit['8']
$iReturn['3'] = $iSplit['12']
Return $iReturn
EndFunc

Hope this helps :) !

- John

Did this work for you? Cause it doesnt for me.

I Copy/Pasted(Im so ashamed lol) into my script and i get this error

E:\Xmine\Xmine.au3(69,45) : WARNING: $Data: possibly used before declaration.
$iSplit = StringSplit (StringTrimLeft ($Data,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Xmine\Xmine.au3(69,45) : ERROR: $Data: undeclared global variable.
$iSplit = StringSplit (StringTrimLeft ($Data,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Xmine\Xmine.au3 - 1 error(s), 1 warning(s)

Am I suppost to just make a global like "Global $data" at the top of my script or is it inteneted to be elsewhere?

Link to comment
Share on other sites

Opps.. didn't fix it xD.. In the function is was using $Data instead of $iLine ...

Fixed function, just paste it over the old one xD...

Func _Extract ($iLine)

Local $iSplit, $iReturn

$iSplit = StringSplit (StringTrimLeft ($iLine, '5'), '> <')

Dim $iReturn['4']

$iReturn['1'] = $iSplit['3']

$iReturn['2'] = $iSplit['8']

$iReturn['3'] = $iSplit['12']

Return $iReturn

EndFunc

Latest Projects :- New & Improved TCP Chat

Link to comment
Share on other sites

Opps.. didn't fix it xD.. In the function is was using $Data instead of $iLine ...

Fixed function, just paste it over the old one xD...

Func _Extract ($iLine)

Local $iSplit, $iReturn

$iSplit = StringSplit (StringTrimLeft ($iLine, '5'), '> <')

Dim $iReturn['4']

$iReturn['1'] = $iSplit['3']

$iReturn['2'] = $iSplit['8']

$iReturn['3'] = $iSplit['12']

Return $iReturn

EndFunc

Well it works, but one problem, it only ever reads line one :S

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...