AutoHotkey Community

It is currently May 25th, 2012, 8:51 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 97 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 7  Next
Author Message
 Post subject:
PostPosted: April 1st, 2007, 6:02 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Ok, 5.37 is out...
Hopefully there aren't too many bugs.
HEXing has been implemented, see documentation (can be easily removed).
Added some functions...
Overloaded the Get() function to accept up to 10 indexes.
Code:
Var := AHKAGet(Array,X,Y,Z) ;etc

Please let me know if you find any bugs.

PS. Numberical sorting works with the AHKASort() function IF the numbers in the array are numbers.

PPS. I left v5.23 up, in case people don't feel like dealing with an experimental (HEX) function implementation

PPPS. The HEXing is not err... "real"? hexing at the moment, so I'll upgrade the algorithm later... still works for storage purposes though


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2007, 7:01 pm 
Offline

Joined: October 28th, 2006, 2:14 am
Posts: 297
Location: US
don't forget to change your post on AHKUpdater about the hex =P

_________________
Changed siggy at request of ahklerner :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2007, 9:17 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
I didn't have much time to work on it yet, so it's still "alpha/beta/whatever" state... I'll get to adding HEX, fixing up any bugs, and adding a bunch of functions to AUF files when I get some time...
(so much work this past week and this weekend =/ ) ...
Thanks for the reminder!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2007, 1:55 pm 
Hi There. Great script, however I noticed that the AHKAConvert function as follows:

Code:
   AHKAConvert(Var)
   {
      global
      local Length := %Var%0
      local Array := AHKANewArray()
      Loop, %Length%
      {
         local TempVar := %Var%%A_Index%
         local Array  := AHKAAdd(Array,TempVar)
      }
      return Array
   }

Doesn't work for me. I am converting the result of
Code:
WinGet, var_name, List, "A Title"

using
Code:
ArrayName := AHKAConvert("var_name")


The problem appears to be the line
Code:
local Length := %Var%0

As I understand it, the size of an array is stored in %Var% not %Var%0. My results from removing the 0 from the end of this line seem to indicate that this is correct as the convert function now works. [/code]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2007, 8:54 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Thank you for your report. The problem lies in the fact that different functions of AHK generate different "generic" arrays.
For example:
StringSplit generates an array which stores its length in arr0
WinGet generates an array which stores its length in arr
I've attempted to create a simple fix using the following:
Code:
AHKAConvert(Var)
{
   global
   local Length := %Var%
   if Length =
      local Length := %Var%0
   local Array := AHKANewArray()
   Loop, %Length%
   {
      local TempVar := %Var%%A_Index%
      local Array  := AHKAAdd(Array,TempVar)
   }
   return Array
}

I've tested it with an empty WinGet, and a full+empty StringSplit
Tell me if it works, because I'm not very familiar with WinGet, and pathetically enough can't make it generate a full array for me (just a size 0 one)

You can either update ur AHKArray by copying the code from here, or simply download the updated version from first page

Thank you for your report


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2007, 10:38 am 
That worked. I suspected as much about different functions producing different kinds of array. Hopefully one day this will be fixed (or the rumored AHKv2.0 with proper arrays is released).


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 9th, 2007, 7:18 pm 
Offline

Joined: June 5th, 2007, 10:57 pm
Posts: 89
Location: USA
Olegbi wrote:
Code:
AHKAFloor(number)
   {
      if number=0
         return 0
      newnumber := 0
      if number<0
      {
         Loop
         {
            if newnumber>%number%
               newnumber--
            else
               return newnumber
         }
      }
      if number>0
      {
         Loop
         {
            if newnumber<%number%
               newnumber++
            else
               return --newnumber
         }
      }
   }


you said that this function is slow
would this be any faster
Code:
fastfloor(number) {
   if number = 0
      return, 0
   if number = % floor(number)
   {
      if number > 0
         return, number + 1
      else return, number - 1
   }
   else return, floor(number)
}


it seemed to me after checking your source code that you wanted to return an integer that fulfilled the following.

abs(floor(number)) > abs(floor(returnvalue)
which is what mine does.

i am uncertain that fastfloor is actually faster than ahkfloor but less lines will definately be executed in fastfloor for most numbers

just a thought.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 6:12 pm 
How about

AHKAString(Array,Delimiter="")
{
Output := ""
Length := AHKASize(Array)
Loop, %Length%
{
Output := Output . AHKAGet(Array,A_Index) . Delimiter
}
return Output
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2007, 6:33 pm 
To olegbl

About the AHKAHEX function, It's the only one that reall work for the strings with `n,`r, Asian characters.

Thanks for the script.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2007, 12:40 am 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Er, I believe (it was a while ago, bad memory XD), that I simply used ascii to transform it to hex, so, as long as the char is within the first 255 (not counting 0, or 256 counting 0) ASCII characters it should be hexified. After that, er, can't really be hexed anyway, but it would probably give some weird results, maybe like characters that would through ASCII add up to the one that one wants....
Anyway, welcome for the script, glad it's of some use =)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2008, 10:16 pm 
Offline

Joined: April 28th, 2008, 10:04 pm
Posts: 4
Hi,

Great script!!! I'm pretty new to AHK and already the built-in fake "array" stuff was annoying me. :)

I registered to post about two weird things I have noticed, one looks to be a straightforward bug and the other I have no idea.

First -
There appears to be a small bug in AHKAGet. The code

Code:
if Index2!=
{
   if AHKAIsArray(Array)
   {
       Array := AHKAGet(Array,Index2)
   }
}
else
{
   return Array
}


is repeated twice, the effect of which is that the 3rd subscript passed to this function does nothing (probably messes up later subscripts as well). Removing the duplicate block makes things work as expected (wheee, multi-dimensional arrays!).

Second -
The AHKAConvert function is behaving strangely for me. Namely, it looks like the variable I pass isn't accessible inside the function. Example:

Code:
strtest=1_2_3_4_5
StringSplit nativearr, strtest, _
newarr := AHKAConvert("nativearr")


I get nothing back in newarr (or more specifically, "[]") and if I put a MsgBox call inside AHKAConvert to spit out nativearr1 (for example) I also get nothing. Very strange. I worked around it for now using

Code:
newarr := AHKANewArray(){
Loop %nativearr0%
   newarr := AHKAAdd(newarr, nativearr%A_index%)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2008, 11:47 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Thank you for the reports.
For the first one, the problem is fixed (typo on my part (ctrl-v)): I'll upload the new version it as soon as I can...
For the second one, the reason is that something is assigned to Var.
Example (As Was In Documentation - Will Change):
Code:
Random := "I am a jolly man"
StringSplit, Random, Random, %A_Space%
Array := AHKAConvert("Random")

Will produce "[]", but
Code:
Random := "I am a jolly man"
StringSplit, Random2, Random, %A_Space%
Array := AHKAConvert("Random2")

Will work.
AHKAConvert first checks "Random" for length, then "Random0", since AHK isn't consistent about the way it returns fake arrays, some have length as "name0", some have it as "name". So, in the "name0" case, make sure "name" doesn't have a value.
I had it wrong in the documentation, but the function is fine.
So, I'll update the docs, hopefully this explains the problem.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2008, 5:57 am 
Offline

Joined: April 28th, 2008, 10:04 pm
Posts: 4
Cool, that worked - thanks!

Next question. :)

How do you do a set of a particular element in a 3-dimensional array? There's no overload for AHKASet like there is for AHKAGet to accomodate multi-dimensional arrays, but I thought I might be able to do something like this:

Code:
TestAHKASet3Dim(array, value, index1, index2, index3)
{
    dim2 := AHKAGet(array, index1)
    dim3 := AHKAGet(dim2, index2)
    dim3 := AHKASet(dim3, value, index3)
    dim2 := AHKASet(dim2, dim3, index2)
    array := AHKASet(array, dim2, index1)
    return array
}


...but I'm seeing some odd behavior after the first set of an array element to a sub-array (this line dim2 := AHKASet(dim2, dim3, index2)).

In a test I have dim2 equal to [[256,2],[100],[2],[4],[]].
I am trying to set the first sub-sub-element to 500 so the result should be [[500,2],[100],[2],[4],[]].
Instead I get [[500,2],[256,2],[100],[2],[4]].

It's like it is inserting the subarray instead of replacing the element I'm telling it to replace.

Is there some other way to do this or is my code messed up? :lol:

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2008, 7:31 am 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
Thank you for the report.
Turns out, the remove function was "broken" for removing nested arrays.
Fixed it, and upgraded it in the process. Now your method will work.
However, it is no longer necessary, I overloaded the add function.
You can now use it to set values up to the 10th dimension.
Ex:
Code:
Arr := AHKASet(Arr, "NewValue", 5, 2, 9, 1, 4)
; Arr[5][2][9][1][4] = "NewValue";

New version (5.41) is available for download.
Also, I've updated the docs to match the capability.

Also, here's my test file in case there's something I might have missed in testing...
Code:
#MaxThreadsPerHotkey 1
#MaxThreads 1
#SingleInstance force

Test:
   ; Create New 3-Dimensional Array :: [A, B, [C1, C2], D, [E1, [E2i, E2ii, E2iii], E3], F]
      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")
   
   ; Lets Change The "D" to a "D+"
      myarr := AHKASet(myarr, "D+", 4)
      result := AHKAGet(myarr, 4)
      MsgBox, %result%
   
   ; Lets Change The "C1" to a "C1+"
      myarr := AHKASet(myarr, "C1+", 3, 1)
      result := AHKAGet(myarr, 3, 1)
      MsgBox, %result%
return

#Include AHKArray.ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2008, 6:34 pm 
Offline

Joined: April 28th, 2008, 10:04 pm
Posts: 4
Works perfectly for my 3-d cases. I appreciate the speedy fix very much!!!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 97 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 7  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group