Azu Posted August 19, 2006 Share Posted August 19, 2006 (edited) Whenever I try to use nested arrays I get an arrow "Array variable subscript badly formated" so I'm guessing I did the format wrong. Can someone please tell me what the proper format is? And please don't tell me to look in the help file.. I already did.. it doesn't tell me how to do this :S Basically I have for $a = 1 to 2 $m[$a]=$a next for $a = 1 to 2 $ab[$a]=random(1,$m[$a],1) next $wd[1]=StringSplit("a/b/c/d","/") if $wd[1[$ab[2]]]="s" then ............. When it gets to the nested array, $wd[5[$ab[4]]], it gives the error and crashes. Please share your ideas on how I can fix this! Thanks! Edited August 19, 2006 by Azu Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 19, 2006 Share Posted August 19, 2006 Hi, sorry, but your script doesn't make any sense. What are you trying to do? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Azu Posted August 19, 2006 Author Share Posted August 19, 2006 I was just trying to make an example of what I meant.. Maybe I can say it better in words... Basically I have an array of a list of words I have another array that makes a random number, never bigger then the amount of words And I want to use the two arrays together, for a stringsplit, to choose one of the words using the random number, E.G. guictrlsetdata($textbox,"$words[3[$randomnumbers[3]]]") Link to comment Share on other sites More sharing options...
Daniel W. Posted August 19, 2006 Share Posted August 19, 2006 it is because you have a number insinde this : "$words[3[$randomnumbers[3]]]" it should be this: "$words[$randomnumbers[3]]" or this: "$words[3]" --------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote] Link to comment Share on other sites More sharing options...
Azu Posted August 19, 2006 Author Share Posted August 19, 2006 $words is an array, there is a bunch of them, each with a bunch of different amounts of words, and the array of the $randomnumbers to match it, so I can use a few next loop to make a series of words in a specific order, the first word being a randomly chose word from $words[1] and the next from $words[2] etc, using $randomnumbers[1] for the first one and then $randomnumbers[2] for the second etc, and then putting them together into a sentence. That is why I need both of them to be arrays, it won't work if one of them is a normal variable.. unless there is a way to nest a variable and use that in an array.. :S Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 19, 2006 Share Posted August 19, 2006 Hi, something like: Global $a[4] = ["1", "3", "HUgo", "huewhd"] MsgBox(0,"", $a[Random(1, UBound($a)-1, 1)]) ??? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Azu Posted August 19, 2006 Author Share Posted August 19, 2006 (edited) no I need to know how to make a nested array, not a normal array. Maybe the correct term is a 2 Dimensional Array or a 3 Dimensional Array or something like that.. :S Edited August 19, 2006 by Azu Link to comment Share on other sites More sharing options...
azeazezar Posted August 20, 2006 Share Posted August 20, 2006 The correct format is... $Arrayname[first dimension][second dimensin][third dimension]...[final dimension] Link to comment Share on other sites More sharing options...
Azu Posted August 20, 2006 Author Share Posted August 20, 2006 (edited) So like$wd[5][$ab[4]]instead of $wd[5[$ab[4]]] ?It's still no working.. gives an error about array variable has incorrect number of subscripts or subscript dimensions range exceeded... :S$wd[5]$ab[4] gives "error in expression"As does $wd[5$ab[4]]And $wd[5][$ab[4]]It should be opening up $wd[5], and opening the $ab[4]'th string in itE.G. $wd[5]=StringSplit("a/b/c","/")And $ab[4]=2And thus return "b"instead it just crashes.. Edited August 20, 2006 by Azu Link to comment Share on other sites More sharing options...
azeazezar Posted August 20, 2006 Share Posted August 20, 2006 for $a = 1 to 2 $m[$a]=$a next for $a = 1 to 2 $ab[$a]=random(1,$m[$a],1) next $wd[1]=StringSplit("a/b/c/d","/") ; Here the array has 1 demension. if $wd[5][$ab[4]]="s"; here it has 2 dimensions... Link to comment Share on other sites More sharing options...
Azu Posted August 20, 2006 Author Share Posted August 20, 2006 I've tried it like that.. it gives the array variable has incorrect number of subscripts or subscript dimensions range exceeded error.. Link to comment Share on other sites More sharing options...
Bundy Posted August 20, 2006 Share Posted August 20, 2006 But in [] you must give index of field ($var[x,y]), so your construction doesn't have sense (i think so ;f). Isn't it easier to use $varx = Random(1,ubound($array)) and then array[$varx]? Link to comment Share on other sites More sharing options...
Azu Posted August 20, 2006 Author Share Posted August 20, 2006 (edited) I didn't want to post up the script I'm working on until I finished it but since my examples suck such horible ass I guess I have no choice.. *snip* Edited August 20, 2006 by Azu Link to comment Share on other sites More sharing options...
azeazezar Posted August 20, 2006 Share Posted August 20, 2006 Well, an array is a variable. Each element of an array should be a single value/string/somethin else, not another array. As each stringsplit returns a new array, they should be stored in a variable i'm gonna try rewrite your code now, i'l post it when i'm done (might take some time) Link to comment Share on other sites More sharing options...
Azu Posted August 20, 2006 Author Share Posted August 20, 2006 (edited) Before, I had $wd[1] $wd[2] $wd[3] etc etc as $wd1 $wd2 $wd3 etc etc, that did work, except I need to use arrays, the variables won't work for how I am going to change it... See how I have for $a = 1 to 6 $clr=$clr&Random(1,9,1) next To make the hex number? I'm going to do something like that with the guictrlsetdata($maintext,$wd[1][$ab[1]]&" "&$wd[2][$ab[2]]&" "&$wd[3][$ab[3]]&" "&$wd[4][$ab[4]]&$wd[5][$ab[4]]&$wd[6][$ab[4]]&$wd[7][$ab[7]]&$wd[8][$ab[5]]&$wd[9][$ab[6]]) A for loop where the number increases each time from 1 to 9 or whatever, and change the stuff around a bit so I can use that increasing variable as the number of the array for the array with the words in it, and the array with the random number that will match that, and then put them all together like I did with the hex number into 1 single string. This will be essential when I made it a lot longer then 9 arrays. I will also need it for other aspects that I am going to add later. But that's besides the point.. basically I need to be able to use arrays such as $wd[1] just like I can use variables such as $wd1 I can use the variable form with another array. I need to be able to use the array form with another array also. Which is why I was referring to it as a nested array, since it's two arrays rather then a variable and an array.. Edited August 20, 2006 by Azu Link to comment Share on other sites More sharing options...
azeazezar Posted August 20, 2006 Share Posted August 20, 2006 (edited) expandcollapse popup#include<guiConstants.au3> Dim $s[9] Dim $m[10] Dim $ab[9] Dim $wd[9999] $m[0] = 12 $m[1] = 24 $m[2] = 45 $m[3] = 10 $m[4] = 8 $m[5] = 2 $m[6] = 8 $m[8] = 2 Local $objSpeach = ObjCreate("Sapi.SpVoice") $objSpeach.Volume = 100 HotKeySet("{insert}", "gen") GUICreate("Thought of the Day", 314, 94) $maintext = GUICtrlCreateInput("", 0, 0, 314, 17, $es_readonly, $ws_ex_transparent) inputcreate(1, 0, 37) inputcreate(2, 39.25, 37) inputcreate(3, 78.5, 37) inputcreate(4, 117.75, 37) inputcreate(5, 157, 37) inputcreate(6, 196.25, 37) inputcreate(7, 235.5, 47) inputcreate(8, 284.5, 30) Func inputcreate($a, $b, $c) $s[$a] = GUICtrlCreateInput("", $b, 18, $c, 17, $es_readonly) EndFunc ;==>inputcreate GUICtrlCreateGroup("", -99, -99, 1, 1) $go = GUICtrlCreateButton("Generate", 48, 68, 89, 25) $cl = GUICtrlCreateButton("Close", 184, 68, 89, 25) $ac = GUICtrlCreateCheckbox("", 85, 38, 10, 10) GUICtrlCreateLabel("Auto", 81, 50) $as = GUICtrlCreateInput("1000", 103, 49, 42, 16) GUICtrlCreateLabel("Speed", 145, 50) $ts = GUICtrlCreateInput("1000", 176, 49, 42, 16) GUICtrlCreateLabel("Talk", 218, 50) $tc = GUICtrlCreateCheckbox("", 222, 38, 10, 10) GUISetState() While 1 $objSpeach.Rate= (GUICtrlRead($ts)) / 500 $1 = GUIGetMsg() If $1 = $gui_event_close Then ExitLoop If $1 = $cl Then ExitLoop If $1 = $go Then gen() If GUICtrlRead($ac) = $gui_CHECKED Then gen() WEnd Func gen() $ab[0] = Random(1, $m[0], 1) $m[7] = 125 If $ab[0] = 10 Then $m[7] = 7 If $ab[0] = 11 Then $m[7] = 3 If $ab[0] = 12 Then $m[7] = 8 For $a = 1 To 7 $ab[$a] = Random(1, $m[$a], 1) Next Do $ab[3] = Random(1, $m[3], 1) Until $ab[3] > 1 Or $ab[4] = 8 $wd[1] = GetRandomElement(StringSplit("I have to/I must/I gotta/I should/Sorry but I gotta/I ought to/I was about to/Can you help me/I still need to/First let me/Oh! I forgot to/I just learned how to/I can't unless I/I need to/I want to/You should/Now I must/I got to/Do you know how to/I forgot I had to/Sorry but I need to/I'd rather/Please/Can you", "/")) $wd[2] = GetRandomElement(StringSplit("water/do/beat/beat up/make/chase/run from/choose/walk with/type/move/grow/try/eat/test/hear/paint/jump over/check on/catch/throw/wax/fix/avoid/smack/slam/find/kiss/ignite/insult/trade with/obfuscate/study/explore/beat up/find something for/wash/kill/sniff/delete/watch a movie with/watch TV with/create/hug/drool on", "/")) $wd[3] = GetRandomElement(StringSplit("some/his/her/the/your/my/any/the best/the worst/a", "/")) $wd[4] = GetRandomElement(StringSplit("cauldron/ton/barrel/lot/horde/little bit/large amount/", "/")) $wd[5] = GetRandomElement(StringSplit("/s//s//s//", "/")) $wd[6] = GetRandomElement(StringSplit(" of / full of / of / full of / of / full of / of /", "/")) $wd[7] = GetRandomElement(StringSplit("hamster/dog/cake/flower/friend/pie/cat/gum/foot/pet lizard/keyboard/house/sister/brother/nuclear missile/wife/slave/president/toy/something/log/mom/mother/Napoleon/bed/grandma/arm/computer/grandpa/cracker/soup/TV/lamp/plant/light bulb/table/dad/shoe/door/telephone/window/DVD/calendar/key/blow-up boat/motorcycle/chimney/wall/door bell/sneaker/sock/yogurt/desk/money/calculator/present/gift/ice cube/mop/frisbee/pizza/pet rock/toaster oven/toaster/wall socket/barber/princess/wheel/stick shift/paper house/french bread/cigar/clock hand/bicycle tire/faucet/nose hair trimmer/poker chip/ashtray/barbecue/bird house/laser printer/stick man/scrabble game/cane/trash compactor/dishwasher/blender/bus token/stamp collection/stapler/copy machine/melted candle/toy box/telescope/microscope/diving board/jump rope/medicine cabinet/lawyer/screen door/no vacancy sign/phone bill/camera/door knob/toilet/plexiglass window/battery charger/paper bag/mushroom/shroom/elevator/escalator/ladder/angel cake/angel/hair dryer/PDA/remote control/pencil set/pencil/fire pit/window blind/blueberry pie/chili/poinsettia", "/")) If $ab[0] = 10 Then $wd[7] = GetRandomElement(StringSplit("secret thing/arm/secretar/canop/dictionar/cand/pant", "/")) If $ab[0] = 11 Then $wd[7] = GetRandomElement(StringSplit("toothbrush/wooden box/candy dish", "/")) If $ab[0] = 12 Then $wd[7] = GetRandomElement(StringSplit("pants/hair/mail/champaign/dental floss/dentures/glasses/goldfish", "/")) $wd[8] = GetRandomElement(StringSplit("s/", "/")) If $ab[0] = 10 Then $wd[8] = GetRandomElement(StringSplit("ies/y", "/")) If $ab[0] = 11 Then $wd[8] = GetRandomElement(StringSplit("es/", "/")) $wd[9] = GetRandomElement(StringSplit("!/./.../?!/!?/!!!/..?/?", "/")) If $ab[4] = 4 Then $wd[6] = GetRandomElement(StringSplit(" of / of / of / of / of / of / of /", "/")) If $ab[3] = 1 And $ab[4] < 4 Then $wd[5] = GetRandomElement(StringSplit("s/s/s/s/s/s/s/s", "/")) If $ab[3] = 10 And $ab[4] < 8 Then $wd[5] = GetRandomElement(StringSplit("///////", "/")) If $ab[3] = 1 And $ab[4] = 4 Then random3() If $wd[5] = "s" Then $wd[6] = GetRandomElement(StringSplit(" of / of / of / of / of / of / of /", "/")) If $wd[3] & " " & $wd[4] & $wd[5] = "a lot" Then $ab[5] = 1 $wd[6] = GetRandomElement(StringSplit(" of / of / of / of / of / of / of /", "/")) EndIf If $ab[4] = 4 Then $ab[3] = 10 If $wd[3]& " " & $wd[4] & $wd[5] = "a little bit" Then $wd[6] = GetRandomElement(StringSplit(" of / of / of / of / of / of / of /", "/")) If $wd[3] & " " & $wd[4] & $wd[5] = "a large amount" Then $wd[6] = GetRandomElement(StringSplit(" of / of / of / of / of / of / of /", "/")) If $wd[3] & " " & $wd[4] & $wd[5] = "a ton" Then $wd[6] = GetRandomElement(StringSplit(" of / of / of / of / of / of / of /", "/")) If $ab[7] = 25 And $ab[4] = 4 Then $ab[4] = 8 If $ab[7] = 25 And $ab[4] < 8 And $ab[4] <> 4 Then $ab[7] = 1 $wd[7] = GetRandomElement(StringSplit("a bed", "/")) EndIf If $ab[0] < 12 Then GUICtrlSetData($maintext, $wd[1] & " " & $wd[2] & " " & $wd[3] & " " & $wd[4] & $wd[5] & $wd[6] & $wd[7] & $wd[8] & $wd[9]) If $ab[0] = 12 Then GUICtrlSetData($maintext, $wd[1] & " " & $wd[2] & " " & $wd[3] & " " & $wd[4] & $wd[5] & $wd[6] & $wd[7] & $wd[9]) For $a = 1 To 7 GUICtrlSetData($s[$a], $ab[$a] & "/" & $m[$a]) Next GUICtrlSetColor($maintext, abc()) For $a = 1 To 8 GUICtrlSetColor($s[$a], abc()) Next If $ab[0] = 12 Then GUICtrlSetData($s[5], "") If $ab[0] < 9 Then GUICtrlSetData($s[8], ":1") If $ab[0] = 10 Then GUICtrlSetData($s[8], ":2") If $ab[0] = 11 Then GUICtrlSetData($s[8], ":3") If $ab[0] = 12 Then GUICtrlSetData($s[8], ":4") ClipPut(GUICtrlRead($maintext)) If GUICtrlRead($tc) = $gui_CHECKED Then $objSpeach.Speak (GUICtrlRead($maintext)) If GUICtrlRead($ac) = $gui_CHECKED Then Sleep(GUICtrlRead($as)) EndFunc ;==>gen Func abc() Local $clr = "0x" For $a = 1 To 6 $clr = $clr & Random(1, 9, 1) Next $clr = Number($clr) Return $clr EndFunc ;==>abc Func random3() Do $ab[3] = Random(1, $m[3], 1) Until $ab[3] > 1 Or $ab[4] <> 4 EndFunc ;==>random3 Func GetRandomElement($array) ; only for 1dimensional arrays for now Return $array[Random(1, $array[0], 1) ] EndFunc ;==>GetRandomElement This script works somewhat like you intended it to do. You can make it work using this. Edited August 20, 2006 by azeazezar Link to comment Share on other sites More sharing options...
Azu Posted August 20, 2006 Author Share Posted August 20, 2006 (edited) Thank you! That Return $array[Random(1, $array[0], 1) ] solves my whole problem and will let me make my script a lot smaller and simpler! I didn't know it would be possible to randomly choose one of the words without putting into the script how many words or are, or else there being a risk of it trying to get a word that isn't there Edited August 20, 2006 by Azu Link to comment Share on other sites More sharing options...
azeazezar Posted August 20, 2006 Share Posted August 20, 2006 No problem, glad i could help ^^ Link to comment Share on other sites More sharing options...
randallc Posted August 20, 2006 Share Posted August 20, 2006 (edited) Hi, You are really just talking about a 2D array, I think; ;nestedarray.au3 #include"array2d.au3" dim $m[3],$ar_ar_wd[4] for $a = 1 to 2 $m[$a]=$a next dim $ab[$a] for $a = 1 to 2 $ab[$a]=random(1,$m[$a],1) next $ar_ar_wd[0]=StringSplit("a/b/c/d","/") ;~ _ArrayDisplay($ar_ar_wd[1],"$wd[1]") $ar_ar_wd[1]=StringSplit("p/s/r/q","/") $ar_ar_wd[2]=StringSplit("a/e/i/o","/") $ar_ar_wd[3]=StringSplit("w/x/y/z","/") $TwoDimArr=_Array2DCreateFromArray($ar_ar_wd) _ArrayViewText($TwoDimArr, '$TwoDimArr') MsgBox(0,"","$TwoDimArr[1][$ab[2]="&$TwoDimArr[1][$ab[2]]) if $TwoDimArr[1][$ab[2]]="s" then MsgBox(0,"","YES $TwoDimArr[1][$ab[2]="&$TwoDimArr[1][$ab[2]])[Array2D in my sig] Best, randall [PS - but I see you have what you need elsewhere...] Edited August 20, 2006 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Azu Posted August 20, 2006 Author Share Posted August 20, 2006 That looks interesting also, maybe I'll find a use for it somewhere. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now