send random line from .txt Topic is solved

Ask gaming related questions (AHK v1.1 and older)
WhoIsALI
Posts: 11
Joined: 25 Feb 2020, 10:36

send random line from .txt

04 Mar 2020, 08:09

I use this script to mix a txt list to - load and send - first line on the .txt
the point is to send random line from .txt each time the script called "pressing f1"

Code: Select all

F2::Reload
F1::

																	 SetWorkingDir %A_ScriptDir%\Data\Text
																	 Write = 5
																	 Loop, 10
																	{
																	  txt := "To.txt"
																	  FileRead, coSubleng, %txt%
																	  FileDelete, %txt%
																	  Sort coSubleng, random U
																	  FileAppend, %coSubleng%, %txt%
																	  List = %txt%
																	 i=0
																	 i++
																	  FileReadline,Line,%List%,%i%
																	  SetKeyDelay, %Write%, 0,
																		{
																		 Sleep,80
																		 Send, %Line%{Enter}
																		 Sleep,10
																		}
																	}
return
it's works ok, but some time it send two or more lines combined (check the screenshot plz), well you guys help,
because i don't seems to find a way to make it work, tried adding multiple different speed here and there, and didn't work.
Attachments
2020-03-04 13_53_17-Window.png
2020-03-04 13_53_17-Window.png (3.82 KiB) Viewed 1929 times
User avatar
Chunjee
Posts: 1452
Joined: 18 Apr 2014, 19:05
Contact:

Re: send random line from .txt

04 Mar 2020, 09:17

I couldn't understand most of your script because its reading a file, deleting it, sorting it, rewriting it? But your goal is to Send random lines so what is the point of all that?

Sends 10 random lines from the file because you have a loop 10

Code: Select all

txt := A_ScriptDir "\input.txt"
WriteDelay = 5

FileRead, coSubleng, % txt
fileArray := StrSplit(coSubleng, "`n")
Loop, 10
{
    ; choose a random entry
    Random, randomNumber, 1, % fileArray.Count()
    Line := fileArray[randomNumber]
    
    SetKeyDelay, %WriteDelay%, 0
    Sleep, 80
    Send, %Line%{Enter}
    Sleep, 10
}
return
Last edited by Chunjee on 04 Mar 2020, 10:29, edited 1 time in total.
WhoIsALI
Posts: 11
Joined: 25 Feb 2020, 10:36

Re: send random line from .txt

04 Mar 2020, 10:16

@Chunjee hi there :).
the script you wrote sends empty lines, when i use random number it's repeats 1 line, and doesn't write it correctly. (check the screenshot).
Sir i'm looking for a script that, sends a random line from text each time it called F1 pressed "F1 =>", Eg :
F1 =>
line89

F1 =>
Line63

F1 =>
Line127

F1 =>
Line1
.
.
.
.
.
etc

Ps : the lines are my students email dresses.
Attachments
2020-03-04 16_03_07-Window.png
2020-03-04 16_03_07-Window.png (4.62 KiB) Viewed 1908 times
User avatar
Chunjee
Posts: 1452
Joined: 18 Apr 2014, 19:05
Contact:

Re: send random line from .txt

04 Mar 2020, 10:30

not true. You are not reading the file correctly. I've edited my script to read from "input.txt" in the same directory because I'm not guessing at your directory structure anymore.
WhoIsALI
Posts: 11
Joined: 25 Feb 2020, 10:36

Re: send random line from .txt

04 Mar 2020, 12:09

@Chunjee
i made some screenshot for you,
i believe there is small thing with Random that is causing this empty lines,
( .ahk ans .txt in the same folder +

Code: Select all

SetWorkingDir %A_ScriptDir%
)
i made Random = 6 <=> it sent the 6th line, therefor the script is working just the random.
plz help, the script you wrote is the best one i found so far.
[*]
Attachments
0.png
0.png (88.03 KiB) Viewed 1886 times
1.png
1
1.png (67.51 KiB) Viewed 1886 times
2.png
2
2.png (76.08 KiB) Viewed 1886 times
WhoIsALI
Posts: 11
Joined: 25 Feb 2020, 10:36

Re: send random line from .txt  Topic is solved

04 Mar 2020, 12:36

Code: Select all


SetWorkingDir %A_ScriptDir%
F2::Reload
F1::
Loop, 10
  {
   txt := "3.txt"
   WriteDelay = 5

   FileRead, coSubleng, %txt%
   fileArray := StrSplit(coSubleng, "`n")
   Loop, Read, %txt%
	{
	   total_lines = %A_Index%
	}
	Random, Var, 1, %total_lines%
	Loop, 1
	{
	    Random, Var, 1, %total_lines%
	    Line := fileArray[Var]
	    
	    SetKeyDelay, %WriteDelay%, 0
					{
					 Send, {Enter}%Line%{Enter}
					}
	}
  }
return

this script worked, what do you think, feel free to improve it

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 45 guests