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

create a text file based on other text files

Post by way1000 » 21 May 2022, 23:15

like on the image

from 1 to 2 "Armour" 2nd column from file 1 to file 2 "Armour = Armour.txt"
from 1 to 3 multiply "85" (6th column) with stats and round result numbers from 3 to 4 2nd column
from 1 to 4 copy over the "Commoner Outfit (M)" text 1st column

the text file 1 is the source and the result is the 4th file with the help of file 2 and 3
Screenshot_6.png
Screenshot_6.png (85.56 KiB) Viewed 1295 times
this is armour.txt
MinAC 0.39
MaxAC 0.80
MinMR 0.30
MaxMR 0.67
MinDC 0.18
MaxDC 0.30
Health 3.31
Mana 3.01
Accuracy 0.07
PoisonResistance 0.02

this is itemstat.txt
Armour = Armour.txt
Bracelet = Bracelet.txt
Emblem = Emblem.txt
Flower = Flower.txt
Helmet = Helmet.txt
Necklace = Necklace.txt
Ring = Ring.txt
Shoes = Shoes.txt
Weapon = Weapon.txt
Attachments
item info stat.txt
(313 Bytes) Downloaded 21 times
edited item stats.txt
(173 Bytes) Downloaded 19 times

User avatar
Chunjee
Posts: 1403
Joined: 18 Apr 2014, 19:05
Contact:

Re: create a text file based on other text files

Post by Chunjee » 22 May 2022, 00:14

I would suggest a csv file or other spreadsheet because that looks like a nightmare to work with or maintain.

Code: Select all

items := [{name: "Commoner Outfit (M)", minAC: 0.39, maxAC: .80, Mana: 3.01, Accuracy: 0.07}
		, {name: "MyCoolArmor (F)", minAC: 0.44, maxAC: .80, Mana: 8, Accuracy: 0.90}]

msgbox, % items[1].name
; => "Commoner Outfit (M)"

msgbox, % items[2].mana
; => 8

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, 06:51

this above doesn't solve it

like in the previous image I'm trying to create "the item info stat.txt" based on those other text files
Screenshot_7.png
Screenshot_7.png (14.95 KiB) Viewed 1221 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_ » 22 May 2022, 09:13

An approach

Code: Select all

FileRead, Edited, edited item stats.txt
Array := StrSplit(Edited, "`t")

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

GenFile := "item info stat.txt"

Loop, Read, %itemtype%.txt, %GenFile%
{
    Pair := StrSplit(A_LoopReadLine, " ")
    FileAppend, % ((A_Index > 1) ? "`n" : "") Title " " Pair[1] "`t" Round(Pair[2]*Multiplier)
}
By the way 85 * 0.02 = 1.7 (You have it written 17), rounding it gives 2
I assume it is a typo :) .

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, 09:34

the result file is identical with Armour.txt

it didn't multiply it
Screenshot_8.png
Screenshot_8.png (16.17 KiB) Viewed 1188 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_ » 22 May 2022, 09:39

Can you check Multiplier := Array[6] value?
I have it working with the file you uploaded (edited item stats.txt), can you try with the same one.

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, 10:06

it's the same file I have and use
Screenshot_9.png
Screenshot_9.png (15.72 KiB) Viewed 1163 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_ » 22 May 2022, 10:29

Tell me what you see when you execute this in the same directory with edited item stats.txt:

Code: Select all

FileRead, Edited, edited item stats.txt
Array := StrSplit(Edited, "`t")

Msg := ""
For Every, One in Array {
    Msg .= "Column " Every ": [" One "]`n"
}

Msgbox, % Msg

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, 10:32

Screenshot_10.png
Screenshot_10.png (17.05 KiB) Viewed 1150 times

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

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

Post by Smile_ » 22 May 2022, 11:21

Then it is something with armour.txt, I believe there is tab before each value, I used the space as delimiter (which seems to be wrong) to get it.
Your quote for that file had space by the way.
Try this:

Code: Select all

FileRead, Edited, edited item stats.txt
Array := StrSplit(Edited, "`t")

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

GenFile := "item info stat.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)
}
Last edited by Smile_ on 22 May 2022, 11:27, edited 1 time in total.

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, 11:27

thanks a lot

you saved me from a lot of work

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

Re: create a text file based on other text files

Post by Smile_ » 22 May 2022, 11:28

Ah good to see it works. Was my please to help! :thumbup:

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, 11:32

how to make it so it can work with more than one text line, like more entries on the main file

.
Screenshot_11.png
Screenshot_11.png (22.17 KiB) Viewed 1098 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_ » 22 May 2022, 11:36

Does 2, 3, 4 included in the file name?
You may try

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)
    }
}
If you got a lot of lines i suggest to use file object method instead.(Faster)
Last edited by Smile_ on 22 May 2022, 12:45, edited 1 time in total.

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, 12:42

they're included

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

Re: create a text file based on other text files

Post by Smile_ » 22 May 2022, 12:45

Well I assume it should work like that if the full name is always in the second column.

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, 12:57

now i have 4 items rows


.
Screenshot_12.png
Screenshot_12.png (15.61 KiB) Viewed 945 times
it gives me only the first (item name)

.
Screenshot_13.png
Screenshot_13.png (23.25 KiB) Viewed 945 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_ » 22 May 2022, 13:33

Look in your folder you should find them indexed with numbers from 1 to 4.

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, 13:44

Smile_ wrote:
22 May 2022, 13:33
Look in your folder you should find them indexed with numbers from 1 to 4.
it's:
.
edited item stats.txt
Armour.txt
item info stat.txt
.
in the same folder

.
where's the index?

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

Re: create a text file based on other text files

Post by Smile_ » 22 May 2022, 14:16

Indexed like this:

item info stat 1.txt
item info stat 2.txt
item info stat 3.txt
item info stat 4.txt


There are not?

Post Reply

Return to “Gaming Help (v1)”