Jump to content

Array Badly Formatted... ??


Recommended Posts

I am trying to make a map with little 16x16 rects for each 'coordinate'. Now I have the map size already set in a two dimensional array, and another array that will hold the GUI Graphic ID so I can loop through them and tell whether one was clicked or not (If it was clicked then change the graphic color and set ANOTHER two dimensional array value at the position of the map coordinate).

But besides that I can't seem to get past this "Array badly formatted error"...

My code:

;----INCLUDES----;
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>


Global Const $mapX = 51
Global Const $mapY = 31
Global Const $IMGX = 16
Global Const $IMGY = 16

Global $labryinthMap[$mapY,$mapX] ;Our maze
Global $GUID[$mapY,$mapX] ;Holds each GUI graphic ID so we can check if it was clicked
Global $posX = 16
Global $posY = 16

GUICreate("Labyrinth", 900, 900)

Local $y, $x
for $y = 0 To $mapY
    $posX = $IMGX ;Reset posX to start position
    $posY += $IMGY ;Increase Y axis by 16 (img size)
    for $x = 0 To $mapX
        $GUID[$y,$x] = GUICtrlCreateGraphic($posX, $posY, $IMGX, $IMGY)
        GUICtrlSetGraphic( $GUID[$y,$x], $GUI_GR_RECT, $posX, $posY, $posX + 16, $posY + 16)
    Next
    MsgBox(0, "", "Row " & $y & " complete.")
Next

Local $msg
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

On a side note, how do I draw a rect in a certain color? I didn't see any values to set in GUICtrlSetGraphic for the color.

Thanks.

Link to comment
Share on other sites

  • Moderators

CheeseBiscuit,

Autoit arrays have each dimension inside square brackets, not comma-separated: :)

; Bad
Global $labryinthMap[$mapY,$mapX]

; Good
Global $labryinthMap[$mapY][$mapX]
As for graphics colour, the first parameter in my Help file page for GUICtrlSetGraphic is $GUI_GR_COLOR. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

CheeseBiscuit,

Autoit arrays have each dimension inside square brackets, not comma-separated: :)

; Bad
Global $labryinthMap[$mapY,$mapX]

; Good
Global $labryinthMap[$mapY][$mapX]
As for graphics colour, the first parameter in my Help file page for GUICtrlSetGraphic is $GUI_GR_COLOR. ;)

M23

 

Oh I see...

Now I have another error, it says incorrect number of subscripts or dimension range exceeded. On this line:

GUICtrlSetGraphic( $GUID[$y][$x], $GUI_GR_RECT, $posX, $posY, $posX + 16, $posY + 16)

Which is impossible, because its set to 31 and 51.. The Y for loop only goes to 31 and the X for loop goes to 51, so I don't see how the range was exceeded? Are these not zero based?

Link to comment
Share on other sites

  • Moderators

CheeseBiscuit,

You declare the array as [31][51] - so the max index is [30][50] and you are trying to access [31][51]. ;)

So either declare the array as $GUID[$mapY + 1][$mapX + 1] or loop one less time. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...