Script not displaying MsgBox message

Ask gaming related questions (AHK v1.1 and older)
GoneFishing
Posts: 126
Joined: 20 May 2022, 16:17

Script not displaying MsgBox message

Post by GoneFishing » 24 May 2022, 08:22

This script is part of a larger script for automating testing in a game (which ahk is of course perfect for). It is supposed to look at a log file and scan the last line for a keyword. If it finds the keyword it then should look at the last 2 digits of the number (separated from the keyword by a whitespace) and if it finds a match it should print out the number (I'll change it to the behaviour I actually want later. This is just for troubleshooting for now).

The script runs without any syntax errors but I have 3 issues

1. I suspect the syntax of the InStr might be off but not sure.
2. The regex command is slightly off - in it's current form it returns the keyword+white space+full number, not just the "00" I'm looking for. I can't seem to quite get it so it only matches on "00"
3. The MsgBox does not pop up

The script is as follows. The test file is also attached. Any help in fixing so it works as required is appreciated !

Code: Select all

FilePath := A_ScriptDir "\TestLogFile2.txt" ; relative path to file
File := FileOpen(FilePath, "r")
OldLogFileSize := 0
File.Seek(0, 2) ; move the file pointer to the end of the file to start reading newly added lines

Loop
{
	LogFileSize := File.Length
	if (LogFileSize > OldLogFileSize)
	{
		Loop
		{
			if File.AtEOF
				Break
			TextLine := File.Readline()
			If InStr(TextLine, seed)    ;searching for keyword
			{
				RegExMatch(TextLine, "\bseed\s+\d*00$", RFNum)    ;find keyword then match 00 at the end of the number after keyword
				MsgBox, % "The ID is " RFNum ; Display number. Change this to action once working
			}
		}
		OldLogFileSize := LogFileSize
	}
	Sleep, 1000 ; wait one second before checking again (change to whatever)
}
return

Esc::
	File.Close()
	ExitApp
return
Attachments
TestLogFile2.txt
(429.23 KiB) Downloaded 14 times

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Script not displaying MsgBox message

Post by mikeyww » 24 May 2022, 20:25

Your debugging is straightforward, because you can display the values of your variables, functions, and conditional statements. If MsgBox does not appear, then the If is false, right (or break occurred)? Keep at it; backtrack; display your values.

For RegExMatch, you can put your characters of interest in parentheses. You then refer to them as RFNum1, for example. See the documentation for explanation.

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Script not displaying MsgBox message

Post by boiler » 24 May 2022, 22:01

One problem is that you did not put quotation marks around the literal string seed, which you used to have in earlier versions of your script:

Code: Select all

			If InStr(TextLine, seed)
Should be:

Code: Select all

			If InStr(TextLine, "seed")

GoneFishing
Posts: 126
Joined: 20 May 2022, 16:17

Re: Script not displaying MsgBox message

Post by GoneFishing » 25 May 2022, 12:43

It needs a file to be running to test, not a dummy test file that is not being written to. Once I clued in to that it worked as expected. I haven't got a match for the RegEx string yet but I know it will work as I tested on regexe101.com. Just need it in the real file to verify the last component. Thanks for the tips to troubleshot and resolve it. Now I can incorporate it into the larger script being built.

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Script not displaying MsgBox message

Post by boiler » 25 May 2022, 14:34

I have tested scripts that act on running log files by having a dummy log file open in a text editor while the script monitors it. Then when I save it again with a new line or lines, it can act on the new data if appropriate. Basically, you become the manual log file generator. That way you can go ahead and add lines including your "seed" line and not have to wait for the real log file to show the range of inputs that you want to test.

Post Reply

Return to “Gaming Help (v1)”