 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
RaptoR
Joined: 27 Jun 2007 Posts: 22 Location: Earth, Cambrian period
|
Posted: Sun May 04, 2008 12:47 pm Post subject: |
|
|
Hm, it seems that this simple code hangs AHKA:
| Code: | myarr := AHKANewArray("[A, B, [C1, C2], D, [E1, [E2i, E2ii, E2iii], E3], F]")
|
(I tried to use the latest version, 5.42) |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 19
|
Posted: Sun May 04, 2008 5:55 pm Post subject: |
|
|
That's because it is not correct.
First. To use a string like [A, B, [C1, C2] ... ] requires NON-HEXed AHKArray.
Otherwise, you'll have to say something like [97 ,98, [ ... ] ... ].
Second, AHKANewArray takes either 0 parameters, or 2. Never 1.
If 0, it makes an empty array.
If 2, it works like AHKASplit (see documentation).
If you want to use a string this would work:
| Code: | ; For NON-HEXed AHKArray
myarr := "[A, B, [C1, C2], D, [E1, [E2i, E2ii, E2iii], E3], F]"; |
Or:
| Code: | ; For HEXed AHKArray
myarr := AHKANewArray()
myarr := AHKAAdd(myarr, "A")
myarr := AHKAAdd(myarr, "B")
temp := AHKANewArray()
temp := AHKAAdd(temp, "C1")
temp := AHKAAdd(temp, "C2")
myarr := AHKAAdd(myarr, temp)
myarr := AHKAAdd(myarr, "D")
temp := AHKANewArray()
temp := AHKAAdd(temp, "E1")
temp2 := AHKANewArray()
temp2 := AHKAAdd(temp2, "E2i")
temp2 := AHKAAdd(temp2, "E2ii")
temp2 := AHKAAdd(temp2, "E2iii")
temp := AHKAAdd(temp, temp2)
temp := AHKAAdd(temp, "E3")
myarr := AHKAAdd(myarr, temp)
myarr := AHKAAdd(myarr, "F")
; Note: All of these could be Chained, see Documentation. |
How the 2 param AHKArray works:
| Code: | myarr := AHKANewArray("This is an array", " ")
; myarr = [This,is,an,array] |
_________________ Real arrays are here.
Customizable self-updaters are too. |
|
| Back to top |
|
 |
suitedtens
Joined: 28 Apr 2008 Posts: 4
|
Posted: Mon May 05, 2008 7:45 am Post subject: |
|
|
I have another one for you.
Try this (used v5.42):
| Code: | #Include AHKArray.ahk
arr := AHKANewArray()
arr := AHKAAdd(arr, 17)
arr := AHKAAdd(arr, 30)
arr := AHKAAdd(arr, 40)
arr := AHKAAdd(arr, 20)
arr := AHKAAdd(arr, 10)
arr := AHKAAdd(arr, 3)
arr := AHKAAdd(arr, 5)
MsgBox % AHKAMaximum(arr)
MsgBox % AHKAMinimum(arr) |
This gives me a maximum value of 3 and a minimum value of 5.
Looking at the result of the AHKASort that AHKAMaximum/AHKAMinimum use, the sorted array is coming back as:
[5, 10, 17, 20, 30, 40, 3]
Another test case, same array as above but add 11 and 15 to the end (so starting array is [17, 30, 40, 20, 10, 3, 5, 11, 15]):
Now the maximum is 40 but the minimum is 5, and the sorted array comes back as:
[5, 10, 11, 15, 17, 30, 3, 30, 40] |
|
| Back to top |
|
 |
RaptoR
Joined: 27 Jun 2007 Posts: 22 Location: Earth, Cambrian period
|
Posted: Mon May 05, 2008 8:41 am Post subject: |
|
|
| olegbl wrote: | | If you want to use a string this would work: |
Thanks for the explanation.
| olegbl wrote: | | Second, AHKANewArray takes either 0 parameters, or 2. Never 1. |
I found it being kinda strange, because prototype of AHKASplit looks like | Code: | | AHKASplit(String,Char="",CaseSensitive=false) |
where 2 from 3 parameters is optional, therefore passing only 1 parameter to the function is legal  |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 19
|
Posted: Tue May 06, 2008 12:14 am Post subject: |
|
|
Re-RaptoR
Yeah, sorry, doesn't have that.
I might add the functionality of doing something like:
| Code: | | newArr := AHKANewArray("[1,2,[3a,3b],4]") |
When I have time...
Otherwise, I'll at least make it clear in the documentation, which is why I'm making a new js-powered documentation (which is taking me a lot more time than I thought it would...)
Re-suitedtens
I'll work on the sort bug as soon as I can, the darn quicksort probably got screwed up due to a change of format of some other function... _________________ Real arrays are here.
Customizable self-updaters are too. |
|
| Back to top |
|
 |
infogulch
Joined: 27 Mar 2008 Posts: 64 Location: KC, MO
|
Posted: Wed May 07, 2008 4:20 pm Post subject: |
|
|
This is cool. Thnx.
I would like to use it from the lib instead of having to #Include it tho. You'd just have to change the functions to "AHKA_*" from "AHKA*", name the script "AHKA.ahk" and put it in one of the library folders, right? I think that would make it easier on people.
Just an idea. Thanks again!  _________________
 |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 19
|
Posted: Wed May 07, 2008 11:34 pm Post subject: |
|
|
Thanks for the suggestion!
I had no idea AHK could use libraries... New feature I guess?
I'll try to use that in the next version, which should come out
around this weekend (hopefully). _________________ Real arrays are here.
Customizable self-updaters are too. |
|
| Back to top |
|
 |
infogulch
Joined: 27 Mar 2008 Posts: 64 Location: KC, MO
|
Posted: Thu May 08, 2008 3:38 am Post subject: |
|
|
How about a function like : AHKA_Move(RealArray, IndexFrom= , IndexTo= ) ?
To do this right now I'm doing something like: | Code: | ;Example of moving a variable in AHKA. Move Index 5 to 3:
IndexFrom = 5
IndexTo = 3
sIndex := AHKA_Get(RealArray, IndexFrom)
RealArray := AHKA_Remove(RealArray, IndexFrom)
RealArray := AHKA_Add(RealArray, sIndex, IndexTo) | Similar in concept to Swap, but instead shifts the other variables around the one you're moving.
What do you think? _________________
 |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 19
|
|
| Back to top |
|
 |
Guest
|
Posted: Thu May 08, 2008 4:19 am Post subject: |
|
|
For the HEX functions, wouldn't this work? Your functions seem longer and more complicated than they need to be.
| Code: | ChrToHex(char)
{
If (StrLen(char) != 1)
{
;ERROR
Return 0
}
IntFormat := A_FormatInteger
SetFormat, Integer, H
char := RegExReplace(asc(char), "^0x", "")
char := StrLen(char) == 1 ? "0" . char : char
SetFormat, Integer, %IntFormat%
Return char
}
ChrFromHex(char)
{
If (StrLen(char) != 2 || !RegExMatch(char, "\d\d"))
{
;ERROR
; Have to return a multi-character string because "0" is an acceptable return value
Return "00"
}
IntFormat := A_FormatInteger
SetFormat, Integer, H
char := chr("0x" . char)
SetFormat, Integer, %IntFormat%
Return char
}
StrToHex(str)
{
Hstr := ""
Loop, parse, str
{
Hchr := ChrToHex(A_LoopField)
If (Hchr == 0)
{
;ERROR
Return 0
}
Hstr .= Hchr
}
Return Hstr
}
StrFromHex(str)
{
If (StrLen(str)/2 != StrLen(str)//2))
{
;ERROR
Return 0
}
Hstr := ""
Loop, parse, str
{
If (A_Index/2 != A_Index//2)
Continue
Hchr := SubStr(A_LoopField, A_Index/2, 2)
Hchr := ChrFromHex(Hchr)
If (Hchr == "00")
{
;ERROR
Return 0
}
Hstr .= Hchr
}
Return Hstr
} |
|
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 19
|
Posted: Thu May 08, 2008 5:18 am Post subject: |
|
|
Yup, that's much better I think.
I didn't look up AHK's HEX function when I was putting mine in.
I changed it, so that'll be updated for next release as well.
Progress:
- HEXing Optimized
- Sorting fixed (rewrote the quicksort)
- Move function implemented
- Changed into AHKA.ahk Library (all functions are now AHKA_* rather than AHKA*)
- Note: For non-Library users: #include AHKA.ahk is still possible
I'll post the new version "officially" as soon as I can get the documentation for it done. For now, I'll put up the "alpha" version XD. PS. It'll jump to v6, since the new documentation thing is a lot of work (too much json), and worth a bunch of update points XD.
"ALPHA" Version Here
Thanks to everyone for your support! _________________ Real arrays are here.
Customizable self-updaters are too. |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 19
|
Posted: Thu May 08, 2008 10:52 pm Post subject: |
|
|
Thanks to infogulch for pointing out that the new HEX function which use SetFormat, only work for integer/float values. The method has been reverted back, and the alpha will now work with all characters. _________________ Real arrays are here.
Customizable self-updaters are too. |
|
| Back to top |
|
 |
BLooM2
Joined: 05 May 2008 Posts: 14 Location: China
|
Posted: Sat May 10, 2008 2:59 pm Post subject: |
|
|
thanks it is so useful, expect that you could finish documentation _________________ Intensively appeal for founding Chinese forum !Fantasy OnLine |
|
| 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
|