create a text file based on other text files Topic is solved

Ask gaming related questions (AHK v1.1 and older)
way1000
Posts: 90
Joined: 20 Jun 2016, 02:19

Re: create a text file based on other text files

Post by way1000 » 22 May 2022, 14:19

no, it's only one
all in one file

way1000
Posts: 90
Joined: 20 Jun 2016, 02:19

Re: create a text file based on other text files

Post by way1000 » 22 May 2022, 17:57

help plz

way1000
Posts: 90
Joined: 20 Jun 2016, 02:19

Re: create a text file based on other text files

Post by way1000 » 22 May 2022, 18:05

the script works as the latest version but doesn't support many entries (rows) on "edited item stats.txt"


.

Code: Select all

Loop, Read, edited item stats.txt
{
    Array := StrSplit(A_LoopReadLine, "`t")

    Title := Array[1]
    Itemtype := Array[2]
    Multiplier := Array[6]

    GenFile := "item info stat " A_Index ".txt"
    Loop, Read, %itemtype%.txt, %GenFile%
    {
        RegExMatch(A_LoopReadLine, "[a-zA-Z]+", Type)
        RegExMatch(A_LoopReadLine, "\d+\.\d+", Value)
        FileAppend, % ((A_Index > 1) ? "`n" : "") Title " " Type "`t" Round(Value*Multiplier)
    }
}
Attachments
item info stat.txt
(936 Bytes) Downloaded 14 times
edited item stats.txt
(693 Bytes) Downloaded 14 times
Armour.txt
(132 Bytes) Downloaded 13 times

User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: create a text file based on other text files

Post by Smile_ » 23 May 2022, 15:04

@way1000
Here we go again,
try this
Just make sure the following are correct:

in edited item stats.txt
1 - Column 1 is not empty.
2 - Column 2 is a file name without the .txt extension already exists.
3 - Column 3 is a valid integer.


in the targeted file name:
1 - Column 1 is not empty.
2 - Column 2 is a number with decimal point.

Code: Select all

SUCESS := "You can press Generate button now to display the final results"
FAILURE := "Sorry something went wrong!"
. "`n`nOne or more of the following conditions was occured!"
. "`n- 1st column is empty"
. "`n- The filename in the 2nd column doesn't exist"
. "`n- 6th column is not a valid number"
;-------------------------------------------------------------------------------------------------
Gui, Font, s10 Bold, Calibri
Gui, Add, Edit, w400 vInput
Gui, Add, Button,, Select
Gui, Add, Edit, vLog ReadOnly w400 r20 +HScroll
Gui, Add, Button,, Generate
Gui, Show
Return

ButtonSelect:
    FileSelectFile, Filepath,, % A_ScriptDir, Select the input file, *.txt
    If (Filepath) {
        FileObj := FileOpen(Filepath, "r"), FileObj.Pos := 0
        Log := "", CollectedRowsData := {}
        While !FileObj.AtEOF() {
            Column := StrSplit(FileObj.ReadLine(), "`t")
            If ((Column[1] != "") && FileExist(Column[2] ".txt") && (Column[6] ~= "\b\d+\b")) {
                CollectedRowsData[A_Index] := [Column[1], Column[2] ".txt", Column[6]]
                Log .= "Row " A_Index " Input file loaded successfully`n"
            } Else {
                Log .= "There is an error loading row number " A_Index "`n"
            }
        }
        GuiControl,, Log, % Log (InStr(Log, "successfully") ? "`n" SUCESS : "`n" FAILURE)
        FileObj.Close()
    }
Return

ButtonGenerate:
    While (Array := CollectedRowsData.RemoveAt(1)) {
        Log .= "`nFile name " Array[2] " - Row " A_Index ":`n`n"
        FileObj := FileOpen(Array[2], "r"), FileObj.Pos := 0
        While !FileObj.AtEOF() {
            RegExMatch(FileObj.ReadLine(), "\b([a-zA-Z]+).*(\d+\.\d+)\b", Match)
            If (Match1 != "" && (Match2 ~= "\b\d+\.\d+\b")) {
                Log .= Array[1] "`t" Match1 "`t" Round(Match2 * Array[3]) "`n"
            } Else {
                Log .= "Incorrect data at line " A_Index "`n"
            }
        }
        FileObj.Close()
    }
    GuiControl,, Log, % Log
Return

GuiClose:
ExitApp
Return

Post Reply

Return to “Gaming Help (v1)”