Rad Posted January 13, 2006 Posted January 13, 2006 Well turns out using one long string to store the value needed for 8 functions and using substrings gets very dirty when you dont use exactly 4 characters. So I want to learn how to use an array! The helpfile makes no sense at all, what the hell?! ; Example 2 - Declaring arrays Dim $weeklyWorkSchedule[$daysWorking] Global $chessBoard[8][8] Local $mouseCoordinates[2], $windowStats[4] Whats with all the variables?! Someone simplify this , I just need a string array size 48 useable in seperate functions/cases etc thanks
Valuater Posted January 13, 2006 Posted January 13, 2006 stringsplit is my favorite example #include <Array.au3> $days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",") ;$days[1] contains "Sun" ... $days[7] contains "Sat" _ArrayDisplay( $days, "Days of the week" ) depends on what you want to do 8)
greenmachine Posted January 13, 2006 Posted January 13, 2006 (edited) Notice it says "Declaring arrays" - these are all examples of arrays being declared. I'll break it down. Dim $weeklyWorkSchedule[$daysWorking] ; <- make an array called $weeklyWorkSchedule of size $daysWorking Global $chessBoard[8][8] ; make a Global array called $chessBoard, 2 dimensions, each of size 8 Local $mouseCoordinates[2], $windowStats[4] ; make 2 Local arrays, one called $mouseCoordinates of size 2 (x and y), one called $windowStats of size 4 (stuff in helpfile, I forget what they are) Now: Dim is complicated.. at least more so than local and global. In the words of Valik, it's a variable scope. What that means is that it depends on the last scope to figure out the new scope. I think... [ edit ] Found his words: I personally hate Dim and think it's a bad idea to use it because it has a variable scope (Re-uses Global if found, otherwise Local). [...]IMO, Dim should be deprecated out of AutoIt but failing that, at least it should be discouraged heavily in favor of the more explicit scope declarators.[ /edit ] Global is easy: create the array so that it can be used throughout the program. Simple enough. Local is also easy: create the array so that it is only used within the scope that it is created (in other words, if you create it within a function for example, it is released once you end the function). What I believe you want is Global $StringArray[48] (or 49 if you want to use 1-48 for stuff and 0 for the size or however many are filled). Edited January 13, 2006 by greenmachine
Rad Posted January 13, 2006 Author Posted January 13, 2006 Ummm no I really dont think I want to jump right in to locals, globals, and 2d arrays atm. I just want the basic way of a single array. I used Warcraft's map editor which is why I know how arrays work, except I dont know how you would start them off. How would I create a variable example $MyVar to be of size 49?
blademonkey Posted January 13, 2006 Posted January 13, 2006 (edited) Ummm no I really dont think I want to jump right in to locals, globals, and 2d arrays atm. I just want the basic way of a single array. I used Warcraft's map editor which is why I know how arrays work, except I dont know how you would start them off. How would I create a variable example $MyVar to be of size 49?First thing is first. you have to declare a variable as an array. The only way i know how to do this is Dim $myvar[49] most user created arrays will have all entries set as 0 (the value). you can set individual items in this array by specifying their "index" number (or position in the array). Also most array indexes start at 0 not 1. this is very important when you're looking for your 49th item. it will be $myvar[48]. so $myvar[3] = "String in an Array" will give the fourth item in the array the string value of "String in an Array" a simple and easy test would be to create and display an array. such as this : #include<array.au3> DIM $MyVar[20]; declares the Var MyVar as an array with 20 items, all items are set to '0's. _arraydisplay($myvar,"No Data"); this function will display every item of the $myvar array $myvar[3] = "String in an Array"; Sets the 4 fourth Item in the $myvar array to "String in an Array" _arraydisplay($myvar,"updated"); this function will display every item of the $myvar array hope that helps. I'm pretty new to arrays myself, but i've just used it to create my first Random Password Generator: http://www.autoitscript.com/forum/index.php?showtopic=20062 -Blademonkey Edited January 13, 2006 by blademonkey ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung
Rad Posted January 13, 2006 Author Posted January 13, 2006 (edited) Ohh my head hurts.... $int_x = 0 While $int_x <> 9 $type_normal[$int_x]=number(GUICtrlRead($cstm_input[$int_x][0])) $type_pierce[$int_x]=number(GUICtrlRead($cstm_input[$int_x][1])) $type_magic[$int_x]=number(GUICtrlRead($cstm_input[$int_x][2])) $type_siege[$int_x]=number(GUICtrlRead($cstm_input[$int_x][3])) $type_hero[$int_x]=number(GUICtrlRead($cstm_input[$int_x][4])) $type_chaos[$int_x]=number(GUICtrlRead($cstm_input[$int_x][5])) $int_x=$int_x + 1 Wend Its saying limit was exceeded, now I declared it with: $type_normal= StringSplit("1.00,1.00,1.00,1.50,1.00,0.70,1.00,0.05",",");Normal $type_pierce= StringSplit("1.00,1.50,2.00,0.75,2.00,0.35,0.50,0.05",",");Pierce $type_magic= StringSplit("1.00,1.00,1.25,0.75,2.00,0.35,0.50,0.05",",");Magic $type_siege= StringSplit("1.00,1.50,1.00,0.50,1.00,1.50,0.50,0.05",",");Siege $type_hero= StringSplit("1.00,1.00,1.00,1.00,1.00,0.50,1.00,0.05",",") ;Hero $type_chaos= StringSplit("1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00",",");Chaos The limit exceeded was the $cstm_inpt[][] though, which went like this Dim $cstm_input[8][6] $cstm_input[0][0]=GUICtrlCreateInput("1.00",56,24,32,18,$ES_NUMBER) $cstm_input[1][0]=GUICtrlCreateInput("1.00",56,50,32,18,$ES_NUMBER) $cstm_input[2][0]=GUICtrlCreateInput("1.00",56,76,32,18,$ES_NUMBER) $cstm_input[3][0]=GUICtrlCreateInput("1.50",56,102,32,18,$ES_NUMBER) Etc etc, each time going [0~7] then increase second [], then repeat 6 times (0~5) Now why is it saying its invalid. I've never used a 2d array before so thats probrably one reason. I could REALLY use some help with this if anyone has msn add wc3gianthalfling@hotmail.com, thanks! Ill still use the forums though, untill I get someone smart enough to help EDIT~Turns out i was just missing a few )'s xD Still doesnt work yet b/c I have to convert approx 48*3 standard variables into 2d arrrays... cya next week ... not Edited January 13, 2006 by Rad
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