AutoHotkey Community

It is currently May 26th, 2012, 7:20 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 83 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject:
PostPosted: February 5th, 2009, 7:22 am 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Ah, bmcclure, you're using the named indexes wrong. Note the syntax on the front page:
SA_Set( Array, Val, [nIdx="+1", Insert=false, giveName=""] )

The nIdx params are only for referencing a name, not creating one. I wanted to avoid some issues when I set that up, but maybe it's not worth the trouble.

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2009, 10:59 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Ah, thanks for that! Fixing it in my code, and will report back if I have further trouble.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Problems with 3D arrays
PostPosted: June 1st, 2009, 4:51 am 
Offline

Joined: May 31st, 2009, 6:40 am
Posts: 12
Having some trouble with creating a 3D array.

I have a list of files with data associated with them


Code:
[file1 | iso | input_string | name | output_dir | source ]
[file2 | iso | input_string | name | output_dir | source ]
[file3 | vts | input_string | name | output_dir | source ]
[file4 | vts | input_string | name | output_dir | source ]


Without documentation or examples it is going to be difficult for me to code this. Would appreciate some help.

Excuse my ignorance and thanks for your help!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2009, 7:23 pm 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
I haven't worked on SimpleArray for a while now, so those of you following this may be happy to know that I'm working on it again. I'll be adding some new functions (sort, swap, join, find, and convert from psuedo array and convert from delimited string, + others) along with restructuring functions (e.g. changing functions to be recursive) and adding better documentation and examples.

By the way, if you have any ideas for new functions/different functionality, now would be the time to ask for it. :D

I'm hoping to be done with it by the end of this weekend, but I wouldn't be holding my breath if I were you. ;)

Thanks!

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2009, 9:00 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Support ++

* Replace items X with Y in Array

Example, replace 1 with 5
before: 1-2-3-4-1-2
after: 5-2-3-4-5-2

* Remove duplicate entries in Array without affection order (e.g. not a Sort Unique)

Example, keep first occurance of 1 2 7 8 remove subsequent ones
before: 8-7-5-4-1-2-6-7-1-2-8-a
after: 8-7-5-4-1-6-a

Can't wait :wink:

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2009, 12:10 am 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Hi guys. Sorry I couldn't push the update yet, I was gone pretty much all weekend long. To make up for it, I'll give a partial release. Hope you guys like it. :D

SimpleArray v3.1

Find information about the update, including new and changed features and ToDo inside. Some functions already have their documentation in them.

I haven't tested it throughly yet, so there may still be bugs. I'm not releasing this on the first post because I hope to update it by the end of this week.

Thanks!

Edit:
Oops, these should be added to the ToDo: Create Unique, Create Replace
(thanks for the suggestions :D )

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 11th, 2009, 12:49 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Quick test report 3.1:

New SA_Get, SA_Del, SA_Set seem to work OK for me

Tested:

SA_ConvertDelimited: OK
SA_Find: OK
SA_FindCnt: OK
SA_Join: OK
SA_ConvertPsuedo: Example would be appreciated

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 11th, 2009, 3:27 pm 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
HugoV wrote:
SA_ConvertPsuedo: Example would be appreciated
OK, I guess i owe you guys some examples. :P
Code:
files0 := 0
Loop C\*.*
    files%A_Index% := A_LoopFileFullPath, files0++
SimpleArrayFiles := SA_ConvertPsuedo("files", files0)
Code:
A_0 = %0%
cliArgs := SA_ConvertPsuedo("", A_0)
Can you guess what this does?

Note that this works only on global psuedo arrays. It cannot convert psuedo arrays created local in functions. Also, the SetFormat mode for integers must be decimal for expected results.

Note that SA_Find currently only finds a partial match, but the new version will give you the option for matching part of an element or the entire element. SA_Find also doesn't compare numbers numerically, but as a string, so if you search for "2" and an element has "02" it won't match. (This is for the whole match option) I may add another find function that compares each element, but it will be slower.

A quick example of SA_ConvertDelimited for two dimensions.
Code:
arr := SA_ConvertDelimited("a,b,c|1,2,3|?,*,@|Z,Y,X,W", "|,")

SA_ConvertPsuedo can also accept multiple dimensions, but I can't think of a practical example atm, so here's something i just made up:
Code:
a1_1 := "abc"
a1_2 := "klmno"
a1_3 := "vwx"
a2_1 := "def"
a2_2 := "pqr"
a2_3 := "yz1"
a3_1 := "hij"
a3_2 := "stu"
a3_3 := "234"

arr := SA_ConvertPsuedo("a", "3,3", "_")


While SA_ConvertDelimited works for arrays where the other dimensions are different sizes, SA_ConvertPsuedo doesn't. To get all of the elements of a psuedo array, pass the maximum number of elements that each dimension has. (i.e. if arr1_* has 5 elements and arr2_* has 7 elements, pass "2,7" for the SA_Dims param. Note that there will be two blank elements at the end in the first dimension's first element.)

:D

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 11th, 2009, 7:19 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Thanks for examples, in my first test ConvertPsuedo "failed" because
I passed it as list and not "list" :oops:
Code:
list=a|b|c|d|e
stringsplit, list, list, |
array:= SA_ConvertPsuedo("list",5)
; array = 1-2-3-4-5 --- oops that is a-b-c-d-e of course


Edit:

Re: cliArgs, yes it stores the command line parameters passed on to the script in the array, nice :wink:

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2009, 10:48 am 
can someone demonstrate how to make a simple 2D array? like this?

Seat|Chips
_______________
Index1: 8 | 1500
Index2: 9 | 3000
Index3: 1 | 1500
Index4: 3 | 1500
Index5: 7 | 1500

thanks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2009, 3:57 pm 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Guest: may I first suggest that you make an account? It will only take a moment, and then I'll know for sure that I helped you out, and you'll know when there are updates to this and other threads you post in. :)

To answer your question, there are many ways you could set this up.

To do exactly what you're asking for you could use one of these methods:
Make a delimited list and use SA_ConvertDelimited:
Code:
array := SA_ConvertDelimited("8,1500|9,3000|1,1500|3,1500|7,1500", "|,")

Push it manually:
Code:
array := SA_Set(array, SA_Set(SA_Set("", 8), 1500))
array := SA_Set(array, SA_Set(SA_Set("", 9), 3000))
array := SA_Set(array, SA_Set(SA_Set("", 1), 1500))
array := SA_Set(array, SA_Set(SA_Set("", 3), 1500))
array := SA_Set(array, SA_Set(SA_Set("", 7), 1500))


I have a suggestion though. Based on the information you gave, you might want to use the index as the seat number, like this:
Code:
array := SA_Set(array, 1500, 8)
array := SA_Set(array, 3000, 9)
array := SA_Set(array, 1500, 1)
array := SA_Set(array, 1500, 3)
array := SA_Set(array, 1500, 7)
; it automatically allocates blank elements if you set an element past the end of the array

This way whenever you want to see the number of chips seat number X has, just do something like this:
Code:
chips := SA_Get(array, 8) ;gets the number of chips of seat number 8

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 6th, 2010, 5:54 am 
Offline

Joined: March 3rd, 2010, 10:30 pm
Posts: 1
Location: Canada
Hello infogulch,

I believe there is an error in your code for SA_Len. It fails to notice when an array is not declared. For example, take the following code:
Code:
   x := SA_Set(x, 1)
   x := SA_Set(x, 2)
   y := SA_Set(y, 3)
   MsgBox, % "Len(x)=" . SA_Len(x) . "  Len(y)=". SA_Len(y) . "  Len(z)=" . SA_Len(z)
   if ErrorLevel
      MsgBox, Caught error in length of an undeclared variable.


The outcome for this code is:
Len(x)=2 Len(y)=1 Len(z)=1
And no MsgBox appears afterwards to indicate that SA_Len ran on an undeclared array (ErrorLevel not set).

Therefore, there is no difference between SA_Len in its output for an array with 1 element or 0 elements, and there is an error.

Could you please take a look at this and tell me what you think?
Thank-you!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 6:10 am 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Actually I have considered this before. A blank variable is considered an array of length 1 as it is no different than initializing the array with a blank first element. Though I would be open to considering modifying this behavior given convincing arguments. At the least I will modify the documentation to mention this specifically.

Thanks :-)

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2010, 8:16 pm 
Offline

Joined: April 22nd, 2010, 6:58 pm
Posts: 9
Hi,
Thanks for your simplearray.
I have a little problem:
Code:
#Include simplearray_v3.5_rel.ahk


elemArray := SA_Set(elemArray,"a",1,false,"AAA")
elemArray := SA_Set(elemArray,"b",2,false,"BBB")
elemArray := SA_Set(elemArray,"c",3,false,"CCC")
elemArray := SA_Set(elemArray,true,4,false,"bool")   
elemArray := SA_Set(elemArray,"d",5,false,"DDD")   
myArray := SA_Set(myArray,elemArray,SA_Len( myArray )+1,false, "myArray1")
     

resetVisible("myArray1",false)    
    
resetVisible(name,bool)
{

   global myArray
   elem := SA_Get(myArray,name)
   
   ;pretest
   pretest := SA_Get(elem,"bool")
   indexByName := SA_Idx( elem,"bool")   
   len := SA_Len( elem )   
   outputDebug pretest %pretest% index: %indexByName% len: %len%
   outputDebug %elem%
   outputDebug ------------------------------------------------
   ;pretest 1 index: 4 len: 5   
   ;AAA:aBBB:bCCC:cbool:1DDD:d   
   
   ;test 1, set without index
   elem := SA_Set(elem,bool,"bool")         
   test1 := SA_Get(elem,"bool")
   indexByName1 := SA_Idx( elem,"bool")   
   len1 := SA_Len( elem )
   outputDebug test1 %test1% index: %indexByName1% len: %len1%
   outputDebug %elem%   
   outputDebug ------------------------------------------------
   ;test1 1 index: 4 len: 9   
   ;AAA:aBBB:bCCC:cbool:1DDD:d0   
   ;no value change but length rises to 9
   
   elem := SA_Get(myArray,name)
   
   ;test 2 with index
   elem := SA_Set(elem,bool,4,false,"bool")         
   test2 := SA_Get(elem,"bool")
   indexByName2 := SA_Idx( elem,"bool")   
   len2 := SA_Len( elem )
   outputDebug test2 %test2% index: %indexByName2% len: %len2%
   outputDebug %elem%
   outputDebug ------------------------------------------------
   ;test2 AAA:aBBB:bCCC:c0DDD:d index:  len: 5   
   ;AAA:aBBB:bCCC:c0DDD:d   
   ;length ok but the value is all the array and bool:1 become 0
   elem := SA_Get(myArray,name)
   
   ;test 3 with index and without name
   elem := SA_Set(elem,bool,4)         
   test3 := SA_Get(elem,"bool")
   indexByName3 := SA_Idx( elem,"bool")   
   len3 := SA_Len( elem )
   outputDebug test3 %test3% index: %indexByName3% len: %len3%
   outputDebug %elem%   
   outputDebug ------------------------------------------------
   ;test3 1 index: 4 len: 9   
   ;AAA:aBBB:bCCC:cbool:1DDD:d0   
   ;the same of test1
   
   
   myArray := SA_Set(myArray,elem,SA_IdxName(myArray,name),false, name)
   
   

}

- How can I change a value?
- There's a way to change a value in child array without reassign the child array to parent array?
- There's a function to change a value like this elem := SA_change(elem,newVal,name)?

Thanks.

p.s. My real project have a more complex structure with 3 array level and many function so I post a simplest test :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2010, 11:01 pm 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Quote:
- How can I change a value?

Notes Section in file wrote:
; ! 2.Specify zero or nothing as the second character to overwrite the element
; ! at Idx position, otherwise any positive number to insert Val into that position


I'm sorry this wasn't clear. I'm also sorry that SA_Set() is kindof kludgy to use. :?

Quote:
- There's a way to change a value in child array without reassign the child array to parent array?

Not currently. SA_Get() does support nested arrays, but not SA_Set() as of now.

I'm going to think hard about changing SA_Set() because, honestly, it sucks right now.

_________________
Scripts - License


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Scratch, Xx7 and 18 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