[c++] Math inside of NumGet Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
N_athan
Posts: 40
Joined: 21 Aug 2021, 16:40

[c++] Math inside of NumGet

05 Sep 2022, 19:12

Code: Select all

         
c := NumGet(bits.Scan0 + (y) * bits.Stride + (x) * 4, "uint")

; debug:
c2 := NumGet(bits.Scan0, "uint")
n1 := (y) * bits.stride
n2 := (x) * 4     
c2 := c2 + n1 + n2
Why c and c2 have different values?
What happens when things are summed inside of a NumGet like that?

bits.Scan0 is a unsigned_char*
bits.Stride, x, y are ints


Im trying to reproduce this ahk script into c++, but the value im getting on test is the same as of c2 and not c

Code: Select all

unsigned int value = *(unsigned int*)(this->bits.Scan0);
unsigned int test = (value + (y) * this->bits.Stride + (x) * 4);
teadrinker
Posts: 4408
Joined: 29 Mar 2015, 09:41
Contact:

Re: [c++] Math inside of NumGet

05 Sep 2022, 19:36

Looks like you not completely understand what you do.

Code: Select all

c2 := NumGet(bits.Scan0, "uint")
What is c2 here?
User avatar
boiler
Posts: 17363
Joined: 21 Dec 2014, 02:44

Re: [c++] Math inside of NumGet

05 Sep 2022, 19:42

N_athan wrote: Why c and c2 have different values?
Think of it this way: If a is the value at address 1100, and if b is the value at address 1000, which you then add 100 to, would you expect them to be the same except by random chance?

Adding 100 to an address and getting the value at the resulting address is not the same as adding 100 to the value at that address.
N_athan
Posts: 40
Joined: 21 Aug 2021, 16:40

Re: [c++] Math inside of NumGet  Topic is solved

05 Sep 2022, 20:24

Geek helped me figure out what's going on
in the first, it's a pointer arithmetic on Scan0 then dereference the value

and in the second im just reading the value pointed to by Scan0

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, peter_ahk and 125 guests