Jump to content


Photo

3d array error


  • Please log in to reply
20 replies to this topic

#1 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 02 April 2011 - 01:14 AM

My problem is either the values aren't storing in the arrays or the arrays cannot be drawn the way I'm using them.

___________________________________________
ERROR in
action number 1
of Create Event
for object object0:

Error in code at line 7:
sp_point[0,point[PID,PXY]]=import_sp_point("passwords.sp",0,PID,PXY);
^
at position 21: Unknown variable point

Here is the create event...
sp_name[0]=import_sp_name("passwords.sp",1);
sp_count[0]=import_sp_count("passwords.sp",1);
for (PID=0; PID<sp_count[0]; PID+=1) {
    for (PXY=0; PXY<=1; PXY+=1) {
        sp_point[0,point[PID,PXY]]=import_sp_point("passwords.sp",0,PID,PXY);
        }
    }
sp_name[1]=import_sp_name("passwords.sp",10);
sp_count[1]=import_sp_count("passwords.sp",10);
for (PID=0; PID<sp_count[1]; PID+=1) {
    for (PXY=0; PXY<=1; PXY+=1) {
        sp_point[1,point[PID,PXY]]=import_sp_point("passwords.sp",1,PID,PXY);
        }
    }
and the draw event...
draw_text(x,y,sp_name[0]+": "+sp_count[0]+"#");
for (PID=0; PID<sp_count[0]; PID+=1) {
    for (PXY=0; PXY<=1; PXY+=1) {
        draw_text(x,y,"Point["+PID+","+PXY+"]="+sp_point[0,point[PID,PXY]]+"#");
        }
    }
draw_text(x,y,sp_name[1]+": "+sp_count[1]+"#");
for (PID=0; PID<sp_count[1]; PID+=1) {
    for (PXY=0; PXY<=1; PXY+=1) {
        draw_text(x,y,"Point["+PID+","+PXY+"]="+sp_point[1,point[PID,PXY]]+"#");
        }
    }
I'm too sleepy to spot the error, so can someone please help me out here. Also if anyone knows where I can find an array flattening workaround tutorial, because I've had no luck finding one.
  • 0

#2 kei

kei

    GMC Member

  • GMC Member
  • 187 posts
  • Version:GM8

Posted 02 April 2011 - 06:20 AM

My problem is either the values aren't storing in the arrays or the arrays cannot be drawn the way I'm using them.


___________________________________________
ERROR in
action number 1
of Create Event
for object object0:

Error in code at line 7:
sp_point[0,point[PID,PXY]]=import_sp_point("passwords.sp",0,PID,PXY);
^
at position 21: Unknown variable point

Here is the create event...
sp_name[0]=import_sp_name("passwords.sp",1);
sp_count[0]=import_sp_count("passwords.sp",1);
for (PID=0; PID<sp_count[0]; PID+=1) {
    for (PXY=0; PXY<=1; PXY+=1) {
        sp_point[0,point[PID,PXY]]=import_sp_point("passwords.sp",0,PID,PXY);
        }
    }
sp_name[1]=import_sp_name("passwords.sp",10);
sp_count[1]=import_sp_count("passwords.sp",10);
for (PID=0; PID<sp_count[1]; PID+=1) {
    for (PXY=0; PXY<=1; PXY+=1) {
        sp_point[1,point[PID,PXY]]=import_sp_point("passwords.sp",1,PID,PXY);
        }
    }
and the draw event...
draw_text(x,y,sp_name[0]+": "+sp_count[0]+"#");
for (PID=0; PID<sp_count[0]; PID+=1) {
    for (PXY=0; PXY<=1; PXY+=1) {
        draw_text(x,y,"Point["+PID+","+PXY+"]="+sp_point[0,point[PID,PXY]]+"#");
        }
    }
draw_text(x,y,sp_name[1]+": "+sp_count[1]+"#");
for (PID=0; PID<sp_count[1]; PID+=1) {
    for (PXY=0; PXY<=1; PXY+=1) {
        draw_text(x,y,"Point["+PID+","+PXY+"]="+sp_point[1,point[PID,PXY]]+"#");
        }
    }
I'm too sleepy to spot the error, so can someone please help me out here. Also if anyone knows where I can find an array flattening workaround tutorial, because I've had no luck finding one.


I don't know what the hell are you doing with that... that crazy load of scripts.
But one thing that is you forgot to initialize the array variable named "point".

Edit: Which means you'ven't created the variable, in other words, variable/array "point" do not exist.

Edited by kei, 02 April 2011 - 06:21 AM.

  • 0

#3 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 02 April 2011 - 01:35 PM

The for loop is used outside the script because scripts in gml can't return arrays. The array is supposed to initialize on that line by assigning the value to it. Any other ideas?
  • 0

#4 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 06 April 2011 - 12:06 AM

Bump. I still need help with this. Why am I getting this error if point is an array inside another array. Point is not a variable.
  • 0

#5 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 10 April 2011 - 09:57 PM

Bump, Still need help. Anyone know what's wrong?
  • 0

#6 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 10 April 2011 - 10:01 PM

The loops initialize the sp_point[] array, but you're also using an array called point[] inside as the second array index. Where are you initializing that?

-IMP ;) :)
  • 0

#7 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 11 April 2011 - 08:14 PM

im initializing it by adding the values to it right. In gml you don't have to initialize it before use. So don't need to use var or anything at the start. Just to please you though, I tried. And it still gave me the error. If you think it needs to be initialized, do you mind telling me how.
  • 0

#8 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 11 April 2011 - 08:30 PM

You're adding values to sp_point[], but not to point[]. Doing something like this:

array_1[0, index_array[6,5]]=6

ONLY initializes array_1, not index_array. In my example, you'd need to do something like this:

index_array[6,5]=20;
array_1[0, index_array[6,5]]=6;

I can't tell from your code exactly what the value of the point[] entries are supposed to be, but as long as you do, in fact, give them a value before trying to use them in the sp_point[] indexes, you should be fine.

-IMP ;) :)
  • 0

#9 YellowAfterlife

YellowAfterlife

    GMC Member

  • Global Moderators
  • 3497 posts
  • Version:GM:Studio

Posted 11 April 2011 - 08:56 PM

If you wish, I have made a 3d array system some time ago:
http://yellow.orgfre...ojects/gmk/#a3d
Unlike yours (from what I've seen), it is instance-based, and should be simplier to work with (you actually write a3d_get(x, y, z) to get variable from 3d array).
  • 0

#10 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 12 April 2011 - 08:17 PM

Using instances for arrays is not a good idea cause when the instances are made, other variables and constants are being made and are not needed. Since this is going to be using over 100 arrays most likely, that would probably be too much memory for a computer to handle. I understand what you are saying IceMetalPunk, but I need to be able to use the array later by calling it with the array id, PID, and PXY. If I give a value to the array inside the first array, I can't use it later on in another loop to get the data out of it. I hope you understand what I'm saying. Just thinking about it is confusing me more now. I need something like YellowAfterlife's idea, but not using instances...
sp_point[0,PID,PXY]=import_sp_point("passwords.sp",0,PID,PXY);

  • 0

#11 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 12 April 2011 - 08:49 PM

So you'd simply want to use sp_point[]'s first index as the "x" coordinate, and point[]'s indexes as the "y" and "z" coordinate.

I won't try to rewrite your code; instead, I'll show you how this kind of system would be initialized and used, and you should be able to work on it from there:

array_3d_init()
for (xx=0; xx<sp_x_count; xx+=1) {
  for (yy=0; yy<sp_y_count; yy+=1) {
    for (zz=0; zz<sp_z_count; zz+=1) {
      point[yy,zz]=sp_z_count*yy+zz; /* Calculate a position index based on yy and zz */
      sp_point[xx, point[yy,zz]] = 0; /* Initialize */
    }
  }
}

array_3d_get(x, y, z)
return sp_point[argument0, point[argument1, argument2]];

array_3d_set(x, y, z, value)
sp_point[argument0, point[argument1, argument2]]=argument3;

Technically, you don't even need the point[] array; you can directly use the index y*z_count+z (where x_count, y_count, and z_count are the dimensions of the array). But to be consistent with what you have, I kept the point[] array in there.

-IMP ;) :)
  • 0

#12 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 13 April 2011 - 08:10 PM

Thanks so much. I pretty much understand your idea now. I won't need the first for loop as it won't necessarily go in order. The only thing I don't understand is how y*z_count+z is calculating a position index. Won't some of the indexes be given more than one value. The y will range from 1-infinity and the z will range from 0-1.
So the indexes will be...
1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,....
That will cause a problem by overwriting indexes. If I am misunderstanding this part, can you please tell me what I'm not getting.
  • 0

#13 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 14 April 2011 - 01:18 AM

Thanks so much. I pretty much understand your idea now. I won't need the first for loop as it won't necessarily go in order. The only thing I don't understand is how y*z_count+z is calculating a position index. Won't some of the indexes be given more than one value. The y will range from 1-infinity and the z will range from 0-1.
So the indexes will be...
1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,....
That will cause a problem by overwriting indexes. If I am misunderstanding this part, can you please tell me what I'm not getting.

The z will go from 0-1? So the depth of the array (z_count) is 2. So you'd get the following values:

1*2+0 = 2
1*2+1 = 3
2*2 + 0 = 4
2*2 + 1 = 5

.
.
.
etc.
.
.
.

-IMP ;) :)
  • 0

#14 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 14 April 2011 - 07:34 PM

Oh thought you meant the highest number. So it will work. How did you come up with that. That's one of the array condensing type formulas I was talking about earlier. Could it be used to condense any dimension size or just 3. For example, can I condense a 10 dimension array into a 2 dimension array using a for loop of those functions?

Thanks by the way. That was exactly what I needed, and I'll test it later and tell you how it worked. I'll make sure to put you in the credits and tell you when it is done.
  • 0

#15 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 14 April 2011 - 08:06 PM

So it will work. How did you come up with that.

I just...did :lol: . It just made sense. Think about it: we're trying to reserve chunks of the x-dimension array for the values contained in the other two dimensions. How many values are there? It's the "area" of the other two dimensions, that is, the product of the sizes of those dimensions. Once the space is reserved, we can simply move through each section as a 2D rectangle, where one dimension is the Y and the other's the Z.

Could it be used to condense any dimension size or just 3. For example, can I condense a 10 dimension array into a 2 dimension array using a for loop of those functions?

Technically, it could be modified to work with an arbitrary number of dimensions. But since GM can only handle 2D arrays, the syntax for a 10D array would be ugly as all get-out. It'd end up something like this:

sp_point[a, point1[b, point2[c, point3[d, point4[e, point5[f, point6[g, point7[h, point8[i,j]]]]]]]]];

Like I said, ugly. You're much better off just using the ds_grid structures for N-dimensional arrays with N>3. But note you can only use data structures in the Pro version.

-IMP ;) :)
  • 0

#16 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 14 April 2011 - 08:32 PM

I understand now. The only problem I got when testing was the PID and PXY variables were interfering with the script's PID and PXY variables inside the for loop. I fixed that easy. For some reason when drawing it, the # is not creating a new line. I also tried chr(10) and some others I found on a search but it did not affect it. They are not being drawn either. Any ideas why it's not creating a new line.

Edited by unscmaster, 14 April 2011 - 08:32 PM.

  • 0

#17 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 14 April 2011 - 08:37 PM

When you call draw_text, it starts at the given (x,y) position every time you call it. It doesn't matter what text you drew before; the # at the end of the previous call is irrelevant. Instead, you should add some multiple of PID and PXY to the y-value where you draw the text. Something like y+string_height("A")*(PID*2+PXY). The 2 comes from the fact that for each loop of PID there are 2 loops of PXY.

-IMP ;) :)
  • 0

#18 unscmaster

unscmaster

    GMC Member

  • New Member
  • 946 posts

Posted 14 April 2011 - 08:50 PM

Thanks I get it. The whole array thing works now, but my script for getting the points values is returning -1 error code. That's just something I'll have to find as the code is like 500 lines long.

EDIT: LOL, the error wasn't in my script it was because 0 should be 1...
sp_point[0,PID*2+PXY]=import_sp_point("passwords.sp",0,PID,PXY);
unstead it should be this...
sp_point[0,PID*2+PXY]=import_sp_point("passwords.sp",1,PID,PXY);

Anyways, I fixed it now thanks to you. Now there's just the main part of it I have to code.

Edited by unscmaster, 14 April 2011 - 09:15 PM.

  • 0

#19 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 14 April 2011 - 09:55 PM

I would have pointed that out, but...I have no idea what import_sp_point's code is :lol: . Glad it all works now.

-IMP ;) :)
  • 0

#20 Railgun88

Railgun88

    GMC Member

  • New Member
  • 81 posts

Posted 15 April 2011 - 01:07 AM

In my opinion, so don't troll me if you disagree, but I came up with a better system that utilizes lists as the 3rd degree. Their method has the possibility of being overrode, mine has no possibility of it happening. One minor advantage mine has is simplicity. If you're still interested, just message me and I'll send you some code.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users