# [Example]Maps101- My personal use

## Recommended Posts

A fully detailed "What to know" for Maps101 can be found here

I'm here to explain my opinion over maps, i like it so much, give to autoit someting of object orientet...
I want to talk of the use i got from maps, specificlly Multi-Dimensional Maps

Maps101  usage

```Global \$mObj[]   ; can be stored Global here, local inside a function or somiething like that

\$mObj.instance=1 ;the mObjct . instance was declared to be 1 or true

msgbox(0,"",\$mObj.instance)```

really easy, not?

now something more hard
i was impressed to the semplicity of maps give me to realize an artificial intelligence,
a sort of little game of life (not konoweys)

The maps can give you a multi-Dimensional tipe of array
it's noting that \$array[][] couldn't do
but let me explain how much it's easyer

thats a really simple algorithm that improve autoit object oriented like programming

in this example i use some java syntax like to obtain someting like

string.len

or      character.getPos.x

else   character.getPos.y

```; i have a gridMap
;in one or more slot of the gridMap
;i have an individue, an essence, an object

Global \$aGridMap[10][10] ; declaring the grid map
; the gridMap goes from a range value of 0~9

;now i want to instance some individue, essence or object

;on a grid of 10 x 10 i can declare 100 dinstincte object
;but i need to store it first in a multidimensional-Array

Global \$instance = 2 ;number of object that i want to initialize

Global \$aWorldArray[\$instance][4]
\$aWorldArray[0][0] = 2 ;at this point i select a pos for the obj in the grid  This is the x value
\$aWorldArray[0][1] = 4 ;this is the y vaue
\$aWorldArray[0][2] = 0x00FF00 ;this is the color of the element
\$aWorldArray[0][3] = "fruit" ;this is the type of the element

\$aWorldArray[1][0] = 5 ;same as up
\$aWorldArray[1][1] = 3
\$aWorldArray[1][2] = 0xFF0000
\$aWorldArray[1][3] = "animal"

;this dosen't look great, i really dosn't apprecciate this approach

;now i want to realize a sort of structure where i can modify the parameters how i want.

;_arrayToMaps transform the multidimensional array from world to a specified individue
;\$array is the \$aWorldArray,
;~ the \$n is the instance, the element we want to grab

Func _ArrayToMaps(ByRef \$array, \$n = 0);the byref grab the entire array

Local \$mIndividue[] ;preparing for maps
Local \$mPos[] ;creating the multidimension map for .x .y pos
\$mPos.x = \$array[\$n][0]
\$mPos.y = \$array[\$n][1]
\$mIndividue.getPos = \$mPos ;  with this trick someting magic appens, the .x .y was attached to the getPos node root

\$mIndividue.n = \$n ;remember his own position into the world obj list
\$mIndividue.type = \$array[\$n][3]
\$mIndividue.color = \$array[\$n][2]

;we have now a single Individue from an array wolrd of objct
;but we want do more hazard thing :P let's destroy the compiler, (my brain maybe)

;we want the \$mIndividue Maps store in its own node an entire multidimensional array

\$mIndividue.array = 0 ;a blank array node to the individue

Local \$aMultiDim[2][2] ; a structure that contain two names at [0][0] and [0][1]  and two surname at [1][0] and [1][1]
\$aMultiDim[0][0] = "Mario"
\$aMultiDim[0][0] = "Mary"
\$aMultiDim[1][0] = "noodles"
\$aMultiDim[1][1] = "nuggets"

;let's add the multy dim array to \$mIndividue.array

\$mIndividue.array = \$aMultiDim ;now you have a complete \$mIndividue that contain for example the name...

;How to use  \$mIndividue.array[1][0] to get "noodles" as a string! Absolutely crazy :D i've never seen or use something like that
;i really dosn't think that a map's really need a multidim array but that make the things more easyer

;i want now to operate with the individue structure, then return the map

Return \$mIndividue

EndFunc   ;==>_ArrayToMaps

;i make a function that operate on an individue obj type
Func _changeSometing(ByRef \$mIndividue)

;i want to move my object to an other position then
\$mIndividue.getPos.x = 6
\$mIndividue.getPos.y = 3

;i want to change the color then

\$mIndividue.color = 0x0000FF ;for blue, an hex RGB value, 0x 00 00 ff, on int it was R000 G000 B255

;and i want also read some data from the array node

Local \$string = '' ;make a blanck string that contain the array info
For \$i = 0 To 1
For \$u = 0 To 1
\$string &= \$mIndividue.array[\$i][\$u] & @CRLF ;usage of multidim array into the array map
Next
Next
;then output the array
MsgBox(0, "lets Read the name!", \$string) ;\$string is only the concatenation of \$mIndividue.array

Return \$mIndividue ;return the entire map!

EndFunc   ;==>_changeSometing

;i make now a function that rewrite back the individual information to a multidimensional array World
Func _MapsToArray(ByRef \$mIndividue) ;this time we don't need the position of the object in the array, because it was store in individue.n
Local \$n
\$n = \$mIndividue.n ;get back it's own stacks

\$aWorldArray[\$n][0] = \$mIndividue.getPos.x ;at this point i select a pos for the obj in the grid  This is the x value
\$aWorldArray[\$n][1] = \$mIndividue.getPos.y ;this is the y value
\$aWorldArray[\$n][2] = \$mIndividue.color

\$aWorldArray[\$n][3] = \$mIndividue.type ;useless because the \$mIndividue.type wasn't changed but that eventually restore the value onto the world array obj

;~  \$aWorldArray is stored globally then i don't need to return a parameters
EndFunc   ;==>_MapsToArray

Func Main();i like to write a main function like c
;we have the entire project now let's concatenate

;~  i want my world array of obj goes to an single individue map then
\$aWorld = \$aWorldArray ; i get the array parameter

\$mSingleObjectFromWorld = _ArrayToMaps(\$aWorld) ;given array tipe, return maps type
MsgBox(0, "old Pos",            \$mSingleObjectFromWorld.getPos.x    & @CRLF  &  \$mSingleObjectFromWorld.getPos.y    );read the pos

\$mSingleObjectFromWorld=_changeSometing(\$mSingleObjectFromWorld);lets the function modify someting

MsgBox(0, "new Pos", _
\$mSingleObjectFromWorld.getPos.x    & @CRLF  _
&   \$mSingleObjectFromWorld.getPos.y    )  ;see what's changed

;now restore back the data to a single multidimensional array from each individue

_MapsToArray(\$mSingleObjectFromWorld) ; thats restore the \$mIndividue changes from single obj to the world multidim array of elements
;\$mSingleObjectFromWorld know is index in the array, because it was stored as \$mSingleObjectFromWorld.n  where n is the array index

EndFunc   ;==>_Main

Call("Main")```

easy explanation of possible uses

one examples that took me into java syntax

```Func _simpleString(\$string);transofrm a string to someting like Java
Local \$mapString[]
\$mapString.string = \$string
\$mapString.len = StringLen(\$string)

Local \$chAsci
\$chAsci = StringToASCIIArray(\$string)

For \$i = 0 To UBound(\$chAsci) - 1
\$chAsci[\$i] = Chr(\$chAsci[\$i])
Next

\$mapString.char = \$chAsci

Return \$mapString
EndFunc   ;==>_simpleString

;~-----the script starts here----

\$strin = 'ciao'
\$mString = _simpleString(\$strin)
MsgBox(0,"the string",\$mString.string)
MsgBox(0, "the lenght of the string", \$mString.len)
MsgBox(0, "the first character of the string", \$mString.char[0])
MsgBox(0, "the last character of the string", \$mString.char[\$mString.len - 1])```

isn't this like a well organizated structure?!

Kiss!

##### Share on other sites

Wow, Nice demonstration of using Maps ... Although, I don't understand OOP

P.S I also made a Experimental Maps UDF which contains a function similar to _ArrayToMaps

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

##### Share on other sites

Thank you.
I just I needed see your example to be convinced.
I think it's different from what I've seen before.

Is this feature is included in the latest releas(not beta) ?

Thank you so much for existing, Autoit and it's community is awesome and gave me very much!
I am so grateful so I contributed 100\$ because I feel that this is the right thing to do
If anyone also thinks that he should contribute because he benefits from Autoit, I suggest doing the same

##### Share on other sites

@gil900 Nope, only beta versions

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

##### Share on other sites

OK,

Do you think that will be drastic changes (big script breaking changes) in this feature when it will be relesed in non-beta ?

Thank you so much for existing, Autoit and it's community is awesome and gave me very much!
I am so grateful so I contributed 100\$ because I feel that this is the right thing to do
If anyone also thinks that he should contribute because he benefits from Autoit, I suggest doing the same

##### Share on other sites

@gil900 Who knows? ¯\_(ツ)_/¯, They might even remove it... or change the syntax.

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...