Comparing group results Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Comparing group results

22 Aug 2017, 14:56

Hey guys, I am writing a script which checks numbers constantly and if one of them decreases, it sends a soundbeep.
I was successful with 1 number, but when it comes to a group I hit a wall

Here is what I made with a single number check:
Spoiler
So I started adding more numbers in both loops and I realized I don't know how to finish the script (compare many values)... And if I make lots of toggleable numbers and I toggle to check only specific numbers from the list, how to check only those results?
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Comparing group results

22 Aug 2017, 20:58

Can you share a working script? I am confused by what you mean.

Where are the numbers coming from?

Can numbers increase?

You want to be able to check different numbers independently?

I would run commands on a SetTimer. Maybe a different timer for each number you want to check. I would use these if statements:

Code: Select all

SetTimer, mytimerA, 500

mytimerA:
currentNumberA:=WhereverThatNumberComesFrom
If (currentNumberA=previousNumberA)
   return ; don't do anything else, nothing has changed
else if (currentNumberA>previousNumberA)
   previousNumberA:=currentNumberA ; the number increased, so now we update our historical number to reflect that
else ; the number decreased
   {
   previousNumberA:=currentNumberA ; we update our historical number
   SoundBeep
   SetTimer, mytimerA, Off ; assuming you want to stop checking after it soundbeeps
   }
return
As previousNumberA should start out blank, the first time the timer executes its subroutine, it should evaluate else if (currentNumberA>previousNumberA) as true, and then any successive time through it can be any of the three If statements.
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Comparing group results

23 Aug 2017, 00:57

Hey, thanks for the reply. The number values I get with ReadMemory function so I simplified it to avoid lots of text.

currentNumberA I get like this:
Spoiler
I thought of a way by making a list of rules for each toggleable button in the second loop
Spoiler
But now imagine 20 numbers like that, it will be like 10 pages long with my version :lolno: Is it possible to fit whole "currentnumber1" script into a variable? I could then learn to use settimer like you do and polish the script :dance:
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Comparing group results

23 Aug 2017, 11:37

You can easily do this with an array of all the numbers.

Code: Select all

; start checking numbers
Numpad1::
   currentNums := getNumbers()
   SetTimer, checkNumbers
return

checkNumbers:
   newNums := getNumbers() ; get the new updated numbers
   ; compare each new number with the current number and soundbeep if it's less
   loop % currentNums.length()
      if (newNums[A_Index] < currentNums[A_Index])
         SoundBeep
   currentNums := newNums ; make the new numbers the "new" current numbers
return

getNumbers() {
   nums := []
   num := ; ... get the first number
   nums.push(num)
   num := ; ... get the second number
   nums.push(num)
   ; ...
   return nums
}
This can be further simplified if you get all the numbers in the same way and the only difference is in the memory location.
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Comparing group results

24 Aug 2017, 05:46

obeeb wrote:You can easily do this with an array of all the numbers.
Spoiler
This can be further simplified if you get all the numbers in the same way and the only difference is in the memory location.
Nice script, I was about to make a new topic to ask how to assign a long calculation to a variable but your function made it all clear :dance:
I'll do some tests to learn array comparison like you did but how would you simplify the script if the getnumbers indeed share the same way? There are 3 similar offsets to get the number but to get the next ones you have to add additional middle offset like this:

number 1:
off1
off2
off3 = number1

number 2:
off1
off2
off2
off3 = number2

number 4:
off1
off2
off2
off2
off3 = number3

I want to check like 20 numbers and the last one has 20 offsets in the middle :D
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Comparing group results

24 Aug 2017, 18:40

I don't fully understand, can you show me an example with the first 3 numbers and the last number? Can't you just multiply off2 by the times you need to add it which would be the same as the number of the number?
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Comparing group results

25 Aug 2017, 00:30

obeeb wrote:I don't fully understand, can you show me an example with the first 3 numbers and the last number? Can't you just multiply off2 by the times you need to add it which would be the same as the number of the number?
If rule Toggle3 is true, it reads the number3:

Code: Select all

	if Toggle3
	{
	SetFormat, Integer, Hex
	pointer := ReadMemory(base,PID)
	offset := pointer + offset1
	pointer := ReadMemory(offset,PID)
	offset := pointer + offset2 ;------------------------
	pointer := ReadMemory(offset,PID)
	offset := pointer + offset2 ;------------------------
	pointer := ReadMemory(offset,PID)
	offset := pointer + offset2 ;------------------------
	pointer := ReadMemory(offset,PID)
	offset := pointer + offset1
	pointer := ReadMemory(offset,PID)
	offset := pointer + changingnumberoffset
	SetFormat, Integer, Dec
	changingnumber := ReadMemory(offset,PID)
	}
Number1:

Code: Select all

	if Toggle1
	{
	SetFormat, Integer, Hex
	pointer := ReadMemory(base,PID)
	offset := pointer + offset1
	pointer := ReadMemory(offset,PID)
	offset := pointer + offset2 ;------------------------
	pointer := ReadMemory(offset,PID)
	offset := pointer + offset1
	pointer := ReadMemory(offset,PID)
	offset := pointer + changingnumberoffset
	SetFormat, Integer, Dec
	changingnumber := ReadMemory(offset,PID)
	}
The bigger the number, the more offset2 it has.
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Comparing group results

25 Aug 2017, 00:56

If I understood you correctly the following should work and if it does you can also call readNumber in a loop:

Code: Select all

readNumber(1) ; returns number 1
readNumber(2) ; returns number 2
readNumber(3) ; returns number 3
readNumber(20) ; returns number 20

readNumber(num) {
	SetFormat, Integer, Hex
	pointer := ReadMemory(base,PID)
	offset := pointer + offset1
	pointer := ReadMemory(offset,PID)

	loop % num {
		offset := pointer + offset2 ;------------------------
		pointer := ReadMemory(offset,PID)
	}

	offset := pointer + offset1
	pointer := ReadMemory(offset,PID)
	offset := pointer + changingnumberoffset
	SetFormat, Integer, Dec
	return ReadMemory(offset,PID)
}
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Comparing group results

25 Aug 2017, 08:56

obeeb wrote:If I understood you correctly the following should work and if it does you can also call readNumber in a loop:
Spoiler
Thank you so much for teaching me! At first it didn't work but I read about local and global functions and figured out the function has to be global to read values outside itself. It works like a charm now!
#NewFunctionsFanEmerged :bravo:

By the way, what does "%" indicate in this line?

Code: Select all

loop % num {
Spoiler
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Comparing group results  Topic is solved

25 Aug 2017, 12:54

mast4rwang wrote:By the way, what does "%" indicate in this line? loop % num {
% followed by a space allows you to use expression mode instead of traditional mode.
This is the same as writing loop %num% { and in this case it's a matter of preference.
Your message box can be rewritten using it in the following way: msgbox, % readNumber(1) ", " readNumber(2) ", " readNumber(3)
You can read more about it here: https://autohotkey.com/docs/Variables.htm#retrieving
mast4rwang wrote:Thank you so much for teaching me! At first it didn't work but I read about local and global functions and figured out the function has to be global to read values outside itself. It works like a charm now!
Putting the function into "global" mode is one option and it's ok to do it if it's convenient to you. You can also declare all your constants as static inside the function and only the PID as global, you can see more here: https://autohotkey.com/docs/Functions.htm#Locals
something like this:

Code: Select all

readNumber(num) {
	static base := 0x123456
	static offset1 := 0x10
	static offset2 := 0x20
	static offset3 := 0x50
	
	global PID
	; ...
Now you can improve the getNumbers() function and get all the numbers in a simple loop that will call readNumber(A_Index).
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Comparing group results

26 Aug 2017, 07:27

I'll start working on my script now and I have a feeling it will work out perfectly, thank you obeeb :thumbup:
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Comparing group results

31 Aug 2017, 04:57

obeeb wrote:
mast4rwang wrote:By the way, what does "%" indicate in this line? loop % num {
% followed by a space allows you to use expression mode instead of traditional mode.
This is the same as writing loop %num% { and in this case it's a matter of preference.
Your message box can be rewritten using it in the following way: msgbox, % readNumber(1) ", " readNumber(2) ", " readNumber(3)
You can read more about it here: https://autohotkey.com/docs/Variables.htm#retrieving
mast4rwang wrote:Thank you so much for teaching me! At first it didn't work but I read about local and global functions and figured out the function has to be global to read values outside itself. It works like a charm now!
Putting the function into "global" mode is one option and it's ok to do it if it's convenient to you. You can also declare all your constants as static inside the function and only the PID as global, you can see more here: https://autohotkey.com/docs/Functions.htm#Locals
something like this:

Code: Select all

readNumber(num) {
	static base := 0x123456
	static offset1 := 0x10
	static offset2 := 0x20
	static offset3 := 0x50
	
	global PID
	; ...
Now you can improve the getNumbers() function and get all the numbers in a simple loop that will call readNumber(A_Index).

I've done it like you suggested, I also combined a_index with custom rule where the number is set at the beginning of a loop and if a certain condition is met it adds 1 for the next cycle. I can filter numbers as I like now. Thanks to you and my brilliant mind I finished the script and it wooorks :dance:

Return to “Ask For Help”

Who is online

Users browsing this forum: A_Perry_1984, Bing [Bot], eL Tux, flyingDman, rommmcek and 81 guests