The problematic code snippet is this:
Code: Select all
Loop Files, "Data\Source\*.txt"
{
SplitPath(A_LoopFileName, , , , &X) ; File name is assigned to X, e.g. "dexfile"
RandomRead(X) ; Send file name to RandomRead function
}
RandomRead(N){
Global
List%N% := Fileread("Data\Source\" . N . ".txt") ; Assign the text in Source\N.txt to the variable ListN, e.g. the data in Source\Dexfile.txt is assigned to ListDexfile
Array%N% := StrSplit(List%N%,"`n") ; Split each line in the file into an array item
rand := Random(1, Array%N%.Length) ; Select a random line of text from the array
Syntax := StrReplace(Syntax, "[" . N . "]", Array%N%[rand]) ; Replace any bracketed text inside Syntax with the same filename (e.g. [Dexfile]) with a random line from the text file with the same name
}
I seem to have gotten my code up to speed besides this. I liked being able to spontaneously create dynamic variables in AHK1, but it seems like my approach doesn't utilize best practices. If anyone could help me update this code, I would greatly appreciate it.
Thank you