Sign in to follow this  
Followers 0
AlmarM

2D array help needed

5 posts in this topic

#1 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites



Just a typo i think: you need to swap the X and Y dimensions one way ...

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

or another ...

$aArray[$tmpX][$tmpY] = "blah"

at least, that cured the error for me when $iX <> $iY ...

whim

Share this post


Link to post
Share on other sites

Hmm, yeah thanks for that ;).

Brings new errors inside my game though.


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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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 ...
 

Share this post


Link to post
Share on other sites

Mayby my head wasn't really clear when writing this. Oh well. ;)


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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0