Jump to content
Sign in to follow this  
Natas70

txt file problems

Recommended Posts

Natas70

i have just spent a week magic a script to change the prices on my mtgo bot's price list. It reads a free off the internet .txt file i download and the bot price list. what it does is reads the 2 files into arrays, compares the 2 txt files and converts the free one into the format of the bot's price list and creates a 3rd array, then it writes the array to the bot's price list text file.

i use fileopen, filereadline, filewriteline, and fileclose.

i have it working perfectly, comparing spaces, line numbers, string length and everything is identical to the visible eye, but when i use it on the bot, the bot freezes at 0% read of the pricelist.

i pulled this quote out of the bot manual

Open MTGO3Cards.txt using NotePad (avoid Microsoft Word or other

complex programs if you want to manipulate it, the text has to be pure ASCII.

how do i make this file pure ascii, is it possible, i know the bot programmer uses autoit for the bot, i just assumed he used it for the txt file creation also.

here is a sample of the bot txt

04 000 04 000 001 5DN C Abuna's Chant# 0.025 0.039 0.004 0.005

04 000 04 000 002 5DN C Armed Response# 0.020 0.044 0.005 0.006

04 000 04 000 003 5DN R Auriok Champion# 2.510 5.520 1.950 2.540

04 000 04 000 004 5DN U Auriok Salvagers# 0.041 0.091 0.022 0.029

here is a sample of the free list

10E Abundance 0.260 0.370 1

10E Academy Researchers 0.030 0.070 6

10E Adarkar Wastes 2.880 3.510

here is a sample of the scripts txt file

04 000 04 000 001 5DN C Abuna's Chant# 0.020 0.022 0.010 0.009

04 000 04 000 002 5DN C Armed Response# 0.020 0.022 0.010 0.009

04 000 04 000 003 5DN R Auriok Champion# 3.210 3.531 2.640 2.376

here is the code for the price list script

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@    read the cbs price file      @@@@@@@  
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

dim $cbscardarray [10000]
$counter = 0
$file = FileOpen("C:\Users\Jamtop\Documents\price list updater\CardsMTGO3.txt", 0)
Do
    If @error = -1 Then ExitLoop
    $counter = $counter +1
    $line = FileReadLine($file)
    $cbscardarray[$counter]= $line
until @error = -1
$cbscounter = $counter - 1
fileclose("C:\Users\Jamtop\Documents\price list updater\CardsMTGO3.txt")

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@    read the new price file      @@@@@@@  
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

dim $newcardarray [10000]
$counter = 0
$file = FileOpen("C:\Users\Jamtop\Documents\price list updater\newprices.txt", 0)
Do
    If @error = -1 Then ExitLoop
    $counter = $counter + 1
    $line = FileReadLine($file)
    $newcardarray[$counter] = $line
until @error = -1
$newcounter = $counter - 1
fileclose("C:\Users\Jamtop\Documents\price list updater\newprices.txt")

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@    load the cbs price array        @@@@@@@  
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

dim $cbsarray [($cbscounter+100)] [13]
;@@@@@@@ for speedier condensing of the pricelists
dim $setarray [100][4]
$oldset = " "
$setcounter = 1
;@@@@@@@ for speedier condensing of the pricelists
for $i = 1 to $cbscounter step 1
    $varstart = 25
    $totallen = 49
    $modifier = 0
    $setvar = StringStripWS(StringMid($cbscardarray[$i], 19, 3), 8)
    $setlen = StringLen($setvar)
    if $setlen = 2 then 
                        $varstart = 24
                        $totallen = 48
                        $modifier = 1
    endif   
    $cbsarray [$i] [1] = StringMid($cbscardarray[$i], 1, 3)
    $cbsarray [$i] [2]  = StringMid($cbscardarray[$i], 4, 4)
    $cbsarray [$i] [3]  = StringMid($cbscardarray[$i], 8, 4)    
    $cbsarray [$i] [4]  = StringMid($cbscardarray[$i], 11, 4)           
    $cbsarray [$i] [5] = StringMid($cbscardarray[$i], 15, 4); card number
    $cbsarray [$i] [6] = StringMid($cbscardarray[$i], 19, ($setlen+1) ); card set
;@@@@@@@ for speedier condensing of the pricelists
    if $oldset <> $cbsarray [$i][6] then
        $oldset = $cbsarray [$i][6]
        $setarray [$setcounter][1] = StringStripWS($cbsarray[$i][6], 8)
        $setarray [$setcounter][3] = $i
        $setcounter = $setcounter + 1
    EndIf
    $setarray[$setcounter-1][2] = StringStripWS($cbsarray[$i][5], 8)
;@@@@@@@ for speedier condensing of the pricelists
    $cbsarray [$i] [7] = StringMid($cbscardarray[$i], (23-$modifier), 2); card rarity
    $len = StringLen($cbscardarray[$i])
    $cardlen = $len-$totallen   
;@@@@ check for #
    $a = 0
    do
        if StringMid($cbscardarray[$i], $varstart + $a, 1) = "#" Then
            $b = $a
        EndIf
        $a = $a + 1
    until  ($a + $varstart) >= $len
    $cbsarray [$i] [8] = StringMid($cbscardarray[$i], $varstart, $b); card name
;@@@@ check for " " in sell reg
    $sellregstart = ($varstart + $b + 2)
    $a = 0
    $c = 0
    do
        if StringMid($cbscardarray[$i], $sellregstart + $a, 1) = " " Then
            $c = $a
        EndIf
        $a = $a + 1
    until  ($c <> 0) or ($a + $sellregstart) >= $len
    $cbsarray [$i][9] = StringMid($cbscardarray[$i], $sellregstart, $c);card sell price
;@@@@ check for " "  in sell foil
    $sellfoilstart = ($sellregstart + $c + 1)
    $a = 0
    $d = 0
    do
        if StringMid($cbscardarray[$i], $sellfoilstart + $a, 1) = " " Then
            $d = $a
        EndIf
        $a = $a + 1
    until  ($d <> 0) or ($a + $sellfoilstart) >= $len
    $cbsarray [$i][10] = StringMid($cbscardarray[$i], $sellfoilstart, $d);sell foil price
    $buyregstart = ($sellfoilstart + $d + 1)
    $a = 0
    $e = 0
    do
        if StringMid($cbscardarray[$i], $buyregstart + $a, 1) = " " Then
            $e = $a
        EndIf
        $a = $a + 1
    until  ($e <> 0) or ($a + $buyregstart) >= $len
    $cbsarray [$i][11] = StringMid($cbscardarray[$i], $buyregstart, $e); card buy price
    $buyfoilstart = ($buyregstart + $d + 1)
    $f = $len - $buyfoilstart
    $cbsarray [$i] [12] = StringMid($cbscardarray[$i], $buyfoilstart ); card buy foil price
Next
$cbscardarray = 0
$setcounter = $setcounter - 1
    
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@    load the new price array        @@@@@@@  
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

dim $newarray [$newcounter+1] [5]

for $j = 1 to $newcounter step 1
    
    $newarray [$j] [1] = StringStripWS(StringMid($newcardarray[$j], 1, 3), 8); Rarity
    $newarray [$j] [2] = StringStripWS(StringMid($newcardarray[$j], 9, 45), 4); Name
    $newarray [$j] [3] = StringMid($newcardarray[$j], 72, 6); Sell
    $newarray [$j] [4] = StringMid($newcardarray[$j], 59, 6); Buy
Next    
$newcardarray = 0   
    
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@    condense the new into the cbs     @@@@@@@  
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
$endset = 0
$k = 1
do 
    $noc = 0
    $setstart = 0
    for $m = 1 to $setcounter step 1
        if $setarray[$m][1] = $newarray[$k][1] Then
            $noc = $setarray[$m][2]
            $setstart = $setarray[$m][3]
            $endset = ($setarray[$m][3] + $setarray[$m][2])
            $m = $setcounter
        EndIf
    Next
    for $l = $setstart to $endset step 1
            if StringStripWS($cbsarray [$l][8], 8) = StringStripWS($newarray [$k][2], 8) Then
                    $cbsarray [$l][9] = $newarray [$k][3] & "    " 
                    $cbsarray [$l][10] = StringStripWS($newarray [$k][3], 8) * 1.10 & "  " 
                    $cbsarray [$l][11] = $newarray [$k][4] & "   " 
                    $cbsarray [$l][12] = StringStripWS($newarray [$k][4], 8) * .90 & "   " 
            EndIf
    Next
$k = $k + 1
until $k = $newcounter 

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@    write cbs array to pricelist       @@@@@@@  
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  
$file = FileOpen("C:\Users\Jamtop\Documents\price list updater\CardsMTGO3a.txt", 2)
for $n = 1 to $cbscounter step 1
        $cbsarray [$n][4] = StringMid($cbsarray [$n][4], 1, 2)
        $cbsarray [$n][4] = $cbsarray [$n][4] & " "
        $cbsarray [$n][7] = $cbsarray [$n][7] & "   "
        $cbsarray [$n][7] = StringMid($cbsarray [$n][7], 1, 4)
        $line1 = $cbsarray [$n][1] & $cbsarray [$n][2] & $cbsarray [$n][3] & $cbsarray [$n][4] & $cbsarray [$n][5] & $cbsarray [$n][6] & StringMid($cbsarray [$n][7], 1, 2)
        $line2 = $line  & $cbsarray [$n][8] & "# "  & StringMid($cbsarray [$n][9], 1, 6)  & StringMid($cbsarray [$n][10], 1, 6)
        $line3 = StringMid($cbsarray [$n][11], 1, 6) & StringMid($cbsarray [$n][12], 1, 5)
        $mainline = $line1 & $line2 & $line3
    if $mainline = " " then exitloop
    filewriteline($file, $mainline)
Next
FileClose($file)
msgbox(4096, "File Write Complete", "done" & $n & $cbscounter )

Thanx for any information you can share with me.

James

Share this post


Link to post
Share on other sites
Valuater

I cant test your script directly , however, I noted a couple of things that can cause you a problem

1

$handle = FileOpen("test.txt", 0)

FileClose($handle)***** Close the handle not the actual file because $File still has a value

2

Do not use the same name for any variable and that may help too!

$File1 = FileOpen()

$File2 = FileOpen()

$File3 = FileOpen()

Then closing them...

FileClose($File1)

FileClose($File2)

FileClose($File3)

3

I would have used FilReadToArray() instead of creating my own loop to read the lines... then FileWriteFromArray() too

best of luck

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
Natas70

thanx for the advice, and to the file to array, this was my first script, so i am really new to all the functions.

I will make all the changes and see where i end up.

thankyou once again.

james

Share this post


Link to post
Share on other sites
Natas70

ok, made all the changes except the filetoarray, and i am still having the same problem, the bot will no read the text file at all, any other suggestions

james

Share this post


Link to post
Share on other sites
Valuater

ok, made all the changes except the filetoarray, and i am still having the same problem, the bot will no read the text file at all, any other suggestions

james

No... Sorry, I don't have enough of a grasp of what is written and how it is being read. This goes beyond what I can comprehend without using the bot personally.... and I don't do that

good luck

8)


NEWHeader1.png

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.