[Fixed] Defining and using three dimensional arrays?

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
User avatar
solarsnowfall
Posts: 1581
Joined: Thu Jun 30, 2005 1:44 am

Defining and using three dimensional arrays?

Post by solarsnowfall »

I've been learning how to use one and two dimensional arrays. My latest attempt at a three dimensional array has me stumped.

Code: Select all

int array[2][4][4] = {{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}},
                      {{17,18,19,20},{21,22,23,24},{25,26,27,28},{29,30,31,32}}}; 
Is this defined properly? The problem I'm encountering is when trying to print anything over array[0][3][3], it always returns 0.
User avatar
Sir_Alien
Posts: 863
Joined: Sun Aug 29, 2004 6:15 am
Location: Sydney, Australia
Contact:

Post by Sir_Alien »

If I may be so bold, I would report this as a bug. I myself have had problems with 3d arrays in other situations, and with this example specifically I've tried several different permeatation and commands.

None of these variations show any sort of consitency. Some reach up to 21, some don't make it as high as that, and others just constantly print 0.

In my opinion, there is a bug that occurs with the 3rd dimension.

I'd love for anyone to prove me wrong. Please.
User avatar
Wills
Posts: 1446
Joined: Mon Jan 10, 2005 7:01 pm
Location: The Well of Wishes

Post by Wills »

This, while not serious, is definitely a problem. If mods keep on getting more and more complex, like they're already getting, 3D arrays will be of everyday use. And you can't use them if they're broken, right?

But as of now, I don't think it's a major issue. Randy has more important stuff to program and fix.
User avatar
Risen
Posts: 5263
Joined: Thu Jan 08, 2004 1:02 pm
Location: N44°30' W073°05'

Post by Risen »

Be sure to update your ACC compiler. I ran into some weirdness with arrays not long ago that went away when I updated it.
User avatar
solarsnowfall
Posts: 1581
Joined: Thu Jun 30, 2005 1:44 am

Post by solarsnowfall »

I'm using the latest version as referenced by Bio, to Sir, to me. So unless I'm missing something here....

And yes, I know how to copy the ACC files to my Doom Builder folder.
User avatar
justin024
Posts: 379
Joined: Sun Nov 14, 2004 1:29 am
Location: Illinois
Contact:

Post by justin024 »

Unlike a real programming language's compiler, ACC will compile an explicitly initialized array even if it is missing some stuff which is really annoying.
User avatar
Sir_Alien
Posts: 863
Joined: Sun Aug 29, 2004 6:15 am
Location: Sydney, Australia
Contact:

Post by Sir_Alien »

Just to clarify a couple of points:
  • 1. The version of ACC Solar and I are using is "ACC 1.36" as available from the zdoom.org download page.

    2. I'm not necessarily saying this is a bug with ZDoom; rather I believe it may be a bug with ACC.
And Justin, would you mind elaborating on your comment? I'm interested in understanding what you said, but unfortunately English is my only language! ;)
User avatar
Bio Hazard
Posts: 4019
Joined: Fri Aug 15, 2003 8:15 pm
Location: ferret ~/C/ZDL $
Contact:

Post by Bio Hazard »

Didn't you say it worked for you Sir_Alien?

Solar: Try running the script through ACC manually. Maybe DB is messing something up?
User avatar
Grubber
Posts: 1031
Joined: Wed Oct 15, 2003 12:19 am
Location: Czech Republic
Contact:

Post by Grubber »

ACC is really, really crappy :?. What do you expect from compiler where x isn't the same as 0 + x?
User avatar
Sir_Alien
Posts: 863
Joined: Sun Aug 29, 2004 6:15 am
Location: Sydney, Australia
Contact:

Post by Sir_Alien »

Bio Hazard wrote:Didn't you say it worked for you Sir_Alien?
My apologies; I jumped the gun when we were discussing it recently.
User avatar
solarsnowfall
Posts: 1581
Joined: Thu Jun 30, 2005 1:44 am

Post by solarsnowfall »

Bio Hazard wrote:Try running the script through ACC manually. Maybe DB is messing something up?
Ran ACC from the comand line, copied the output file into the test wad as the BEHAVIOR lump, and still, it won't print anything above array[0][3][3]... :?

Also, if this has anything to do with it, I'm printing it as follows.

Code: Select all

print(d:array[random(0,1)][random(0,3)][random(0,3)]);
Nothing beyond 16 is ever printed, and 0 is printed for everything else.

I've tried something like....

Code: Select all

for (int i=0; i<2; i++)
{
    for (int x=0; x<4; x++)
    {
        for (int y=0; y<4; y++)
        {
            print(d:array[i][x][y]);
            delay(35);
        }
    }
}
And it would count up to 21 before printing 0 for everything else. So in some cases it stops at array[0][3][3], and others at array[1][1][0]. Asside from just printing it, how can I test this? I haven't ruled out my meathods of checking the values as the problem either...
User avatar
justin024
Posts: 379
Joined: Sun Nov 14, 2004 1:29 am
Location: Illinois
Contact:

Post by justin024 »

Sir_Alien wrote:And Justin, would you mind elaborating on your comment? I'm interested in understanding what you said, but unfortunately English is my only language! ;)
Basically what I meant is that this will compile but it shouldn't!

Code: Select all

int arr[3]={3};
So if you were missing part of the array, ACC wouldn't clue you in as to what was wrong which could lead to hard to find errors in large arrays.
User avatar
TheDarkArchon
Posts: 7656
Joined: Sat Aug 07, 2004 5:14 am
Location: Some cold place

Post by TheDarkArchon »

It's like that in C/C++: The missing items can be defined later.
User avatar
solarsnowfall
Posts: 1581
Joined: Thu Jun 30, 2005 1:44 am

Post by solarsnowfall »

justin024 wrote:Basically what I meant is that this will compile but it shouldn't!
Were you referring to the array defined in my first post, or just the one you posted?
User avatar
Risen
Posts: 5263
Joined: Thu Jan 08, 2004 1:02 pm
Location: N44°30' W073°05'

Post by Risen »

solarsnowfall wrote:I haven't ruled out my meathods of checking the values as the problem either...
Well, here's a place to start:

Code: Select all

for (int i=0; i<2; i++)
{
    for (int x=0; x<4; x++)
    {
        for (int y=0; y<4; y++)
        {
            print(s:"["d:i, s:"][", d:x, s:"][", d:y, s:"]: ", d:array[i][x][y]);
        }
    }
}
Note: code not tested for accuracy... but you should get the idea. Also note that I took out the delay. Just check the console after. Much quicker than waiting 30 seconds every time. (then use pgup/pgdn to scroll it, if you didn't know)
Post Reply

Return to “Closed Bugs [GZDoom]”