 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Peter
Joined: 30 Dec 2005 Posts: 448
|
Posted: Tue Nov 17, 2009 5:15 am Post subject: NumGet() not working inside a function? [solved] |
|
|
When using Numget inside the function CheckBytes, it returns mostly wrong values.
The following testscript fills all bytes in bitList with initValue, but Numget reads some other values.
The GetIntAt() function reads always the correct initValue though.
Is there a way to get it right with NumGet in a function? | Code: | showEveryByte := true ; false avoids checking every byte by user
byteCount := 64 , initValue := 123
GrantedCapacity := VarSetCapacity(bitList, byteCount, initValue)
CheckBytes(&bitList, GrantedCapacity) ; test for NumGet in function
; If not in a function, NumGet never causes a problem:
Loop %GrantedCapacity% {
byteNumber := A_index - 1
numByte := NumGet(&bitList, byteNumber, "char")
intByte := GetIntAt(&bitList, byteNumber, 1)
if (showEveryByte || numByte <> initValue || intByte <> initValue){
msgbox, 1, Outside: byte %byteNumber% (V%A_AhkVersion%)
, numByte= %numByte% `nintByte= %intByte% `n(initValue= %initValue%)
IfMsgBox, Cancel
break
}
}
VarSetCapacity(bitList, 0) ; free bitList
ExitApp
F9::ExitApp
return
CheckBytes(pBitList, GrantedCapacity){
; W/ NumGet in a function, it causes always a problem at some byte(s)
global showEveryByte, initValue
Loop %GrantedCapacity% {
byteNumber := A_index - 1
numByte := NumGet(pBitList, byteNumber, "char") ; pBitList or *pBitList does NOT work for me
intByte := GetIntAt(pBitList, byteNumber, 1)
if (showEveryByte || (numByte <> initValue) || (intByte <> initValue)){
msgbox, 1, Inside: byte %byteNumber% (V%A_AhkVersion%)
, numByte= %numByte% `nintByte= %intByte% `n(initValue= %initValue% baseAddress= %pBitList%)
IfMsgBox, Cancel
return
}
}
}
GetIntAt(address, offset, size){ ; replacement for NumGet works always fine
int := 0
Loop %size% {
byteNumber := A_index - 1
int += *(address + offset + byteNumber) << (8 * byteNumber)
}
return int
} |
Last edited by Peter on Tue Nov 17, 2009 7:14 am; edited 1 time in total |
|
| Back to top |
|
 |
hd0202
Joined: 13 Aug 2006 Posts: 174 Location: Germany
|
Posted: Tue Nov 17, 2009 5:55 am Post subject: Re: NumGet() not working inside a function? |
|
|
change the following line without &
| Code: | | CheckBytes(bitList, GrantedCapacity) |
Hubert |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7159
|
Posted: Tue Nov 17, 2009 6:19 am Post subject: |
|
|
Hi Peter..
| Code: | CheckBytes(pBitList, GrantedCapacity){
; W/ NumGet in a function, it causes always a problem at some byte(s)
global showEveryByte, initValue
Loop %GrantedCapacity% {
byteNumber := A_index - 1
numByte := NumGet(pBitList+0, byteNumber, "char") ; pBitList or *pBitList does NOT work for me
intByte := GetIntAt(pBitList, byteNumber, 1)
if (showEveryByte || (numByte <> initValue) || (intByte <> initValue)){
msgbox, 1, Inside: byte %byteNumber% (V%A_AhkVersion%)
, numByte= %numByte% `nintByte= %intByte% `n(initValue= %initValue% baseAddress= %pBitList%)
IfMsgBox, Cancel
return
}
}
} |
|
|
| Back to top |
|
 |
Peter
Joined: 30 Dec 2005 Posts: 448
|
Posted: Tue Nov 17, 2009 7:13 am Post subject: |
|
|
Thanks Skan. Nice trick. While I saw the trick, I remembered it is mentioned in some way in AHK Help as well.
I guess struggling too long with it, that I overlooked that option.
But actually confusing/weird. Suppose you have to do the same with other functions.
I.e. using Sin(x) outside a function and Sin(x+0) inside a function .
I guess the possibility to choose between NumGet(var) and NumGet(&var) is to blame. ( Better get rid of that choice?) |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7159
|
Posted: Tue Nov 17, 2009 7:26 am Post subject: |
|
|
Using pVar+0 was side-effect and Laszlo informed it to Mr.Chris, IIRC.
| Peter wrote: | I guess the possibility to choose between NumGet(var) and NumGet(&var) is to blame. ( Better get rid of that choice?) |
I am unable to comment as I am already accustomed to these current methods.
There was a huge discussion: Choose naming and syntax for built-in Extract/InsertInteger |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|