Jump to content

Declaring a 3-D Array


RealisT
 Share

Recommended Posts

I can't find any documented examples of how to declare a three-dimensional array.

There's absolutely no way I'm going to assign values to each element up front. Not happening. There must be another way!

Here is the general idea of what I want, (only it's incorrect code):

Global $p[720][480][3]

I want to declare a Global variable of three dimensions, with the number of elements per dimension as listed above.

There are far too many elements for me to assign values up front. That's the job of the rest of the script, anyway (For-Next loops and all that).

What's the correct code? I can't find any online examples which involve 3+ dimensions or which don't involve initializers.

Link to comment
Share on other sites

Yes that is how you do it, here is a quick example. Just you can NOT use _ArrayDisplay to show it as that only works up to 2 dimensions thus 3 will not work as I show here.

#include <Array.au3>
Global $array[5][5][5]

For $i = 1 To 4
    For $j = 1 To 4
        For $k = 1 To 4
            $array[$i][$j][$k] = '$k: ' & $k
        Next
        $array[$i][$j][0] = '$j: ' & $j
    Next
    $array[$i][0][0] = '$i: ' & $i
Next
_ArrayDisplay($array)
For $i = 1 To 4
    For $j = 1 To 4
        For $k = 1 To 4
            MsgBox(0,'',$array[$i][$j][$k]) 
        Next
        Msgbox(0,'',$array[$i][$j][0])
    Next
    Msgbox(0,'',$array[$i][0][0])
Next
Edited by Thatsgreat2345
Link to comment
Share on other sites

I am just not seeing why your line works:

Dim $array[4][4][4]

And my line doesn't:

Global $p[$portalWidth][$portalHeight][3]

(or) Global $p[720][480][3]

I also don't see the difference between your 'method' of assigning of variables to my own.

Here is the relevant code:

Global $maxResWidth = 720

Global $maxResHeight = 480

Global $portalWidth = _Min (@DesktopWidth, $maxResWidth)

Global $portalHeight = _Min (@DesktopHeight, $maxResHeight)

Global $p[$portalWidth][$portalHeight][3]

For $mountRow = 1 to $portalHeight

For $mountCol = 1 to $portalWidth

$p[$mountCol][$mountRow][0] = ""

$p[$mountCol][$mountRow][1] = 0

$p[$mountCol][$mountRow][2] = ""

NextNext

Here is the Error msg:

H:\Pauls AutoIt\Pauls Scripts\Graphics\Hologrammer\Draft1.au3 (45) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$p[$mountRow][$mountCol][0] = ""

How is the one script working while the other is not?

Link to comment
Share on other sites

I am just not seeing why your line works:

Dim $array[4][4][4]

And my line doesn't:

Global $p[$portalWidth][$portalHeight][3]

(or) Global $p[720][480][3]

I also don't see the difference between your 'method' of assigning of variables to my own.

Here is the relevant code:

Global $maxResWidth = 720

Global $maxResHeight = 480

Global $portalWidth = _Min (@DesktopWidth, $maxResWidth)

Global $portalHeight = _Min (@DesktopHeight, $maxResHeight)

Global $p[$portalWidth][$portalHeight][3]

For $mountRow = 1 to $portalHeight

For $mountCol = 1 to $portalWidth

$p[$mountCol][$mountRow][0] = ""

$p[$mountCol][$mountRow][1] = 0

$p[$mountCol][$mountRow][2] = ""

NextNext

Here is the Error msg:

H:\Pauls AutoIt\Pauls Scripts\Graphics\Hologrammer\Draft1.au3 (45) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$p[$mountRow][$mountCol][0] = ""

How is the one script working while the other is not?

You have to remember that Arrays on 0 based. Meaning if you declare 4 it actually means 3. Thus you need to add one extra to it.
Link to comment
Share on other sites

Just for reference, this array:

Global $p[720][480][3]

Gives you an array with 1,036,800 elements. While you are allegedly allowed to have 16 million elements before you are violating a technical limitation of autoit, i can't possibly see why you would ever need 1,036,800 elements.

But as to your problem, Thatsgreat2345 is absolutely correct. When you define an array

Dim $Array[3]

the "3" is a count of how many elements are in the array, but they start counting at 0, so the 3 you get are referenced by:

$Array[0], $Array[1], $Array[2]

Notice: 3 Elements, but the last one is a 2.

Edit:

Here is the Error msg:

H:\Pauls AutoIt\Pauls Scripts\Graphics\Hologrammer\Draft1.au3 (45) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

PS - You have an AWESOME name :D:P Edited by Paulie
Link to comment
Share on other sites

Just for reference, this array:

Global $p[720][480][3]

Gives you an array with 1,036,800 elements. While you are allegedly allowed to have 16 million elements before you are violating a technical limitation of autoit, i can't possibly see why you would ever need 1,036,800 elements.

But as to your problem, Thatsgreat2345 is absolutely correct. When you define an array

Dim $Array[3]

the "3" is a count of how many elements are in the array, but they start counting at 0, so the 3 you get are referenced by:

$Array[0], $Array[1], $Array[2]

Notice: 3 Elements, but the last one is a 2.

Edit:

PS - You have an AWESOME name :D:P

Maybe I need a vacation more than I realized. I can't believe I didn't pick up on that! Arrays 101 stuff!

Thank you, all, for your voices of reason. Now I'm off to buy some Rust-remover...

By the way , the reason that the array is so big is that it has to be able to store three pieces of data for each pixel in a video (720x480) frame. Long story.

P.S. Thanks for the moniker-mention.

Edited by RealisT
Link to comment
Share on other sites

By the way , the reason that the array is so big is that it has to be able to store three pieces of data for each pixel in a video (720x480) frame. Long story.

Must not be working in real time video, I get over six seconds just to load an array that size:

Global $p[720][480][3], $i = 0

Global $iTimer = TimerInit()
For $x = 0 To 719
    For $y = 0 To 479
        For $z = 0 To 2
            $i += 1
            $p[$x][$y][$z] = $i
        Next
    Next
Next
MsgBox(64, "Result", "Wrote " & $i & " elements in " & Round(TimerDiff($iTimer)/1000, 3) & " seconds.")

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Must not be working in real time video, I get over six seconds just to load an array that size:

Global $p[720][480][3], $i = 0

Global $iTimer = TimerInit()
For $x = 0 To 719
    For $y = 0 To 479
        For $z = 0 To 2
            $i += 1
            $p[$x][$y][$z] = $i
        Next
    Next
Next
MsgBox(64, "Result", "Wrote " & $i & " elements in " & Round(TimerDiff($iTimer)/1000, 3) & " seconds.")

:D

You're right, and it takes place in my app's "Launch" stage of runtime. This is for a frame-by-frame construction of 3D graphics to be rendered to video. That kind of business is always slower than real-time anyway.

Vector graphics, I'm told, are much faster and are used for gaming and such. I'd be happy to switch over to that as soon as I can eliminate the need to arbitrate object distances (i.e., "Which object gets its pixel displayed in front of the others") with an array!

Thanks again.

Edited by RealisT
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...