Jump to content

2D array help needed


AlmarM
 Share

Recommended Posts

Hey,

I'm currently creating a little game with AutoIt, and it involves a 2D array.

Whenever I use this

Global $iX                = 25
Global $iY                = 25
Global $aArray            [$iX + 1][$iY + 1]

For $tmpY = 0 To $iY
    For $tmpX = 0 To $iX
        $aArray[$tmpY][$tmpX] = "blah"
    Next
Next

There is no problem, everything works.

But as soon as I want to resize the array like this

Global $iX                = 20 ; changed to 20
Global $iY                = 25
Global $aArray            [$iX + 1][$iY + 1]

For $tmpY = 0 To $iY
    For $tmpX = 0 To $iX
        $aArray[$tmpY][$tmpX] = "blah"
    Next
Next

It's gets an out or range error.

Same as this

Global $iX                = 25
Global $iY                = 20 ; changed to 20
Global $aArray            [$iX + 1][$iY + 1]

For $tmpY = 0 To $iY
    For $tmpX = 0 To $iX
        $aArray[$tmpY][$tmpX] = "blah"
    Next
Next

How do I fix this? The problem is that my For loops can only take 2 numbers wich are equal to each other.

EDIT: Typo

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Nice one for Coding Mistakes ;)

dim $aArray[ $iX +1][ $iY +1]

For $tmpY = 0 To $iY

For $tmpX = 0 To $iX

$aArray[ $tmpY ][ $tmpX ] = ...

Next

Next

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...