PDA

View Full Version : NEED HELP C.O.F.F.E.E. Arrays


0010
12-30-2005, 02:01 PM
Hi all !!
i'm new of this language and i've encountered a problem with the multidimensional arrays.
In the 9,5 SDK i've found it's possible declare a two dim. array with the command :

var my_array=new(array,3,3);

the problem is that it doesn't work ... if i try to put some data inside with for example :

my_array[2,2] = something --- or --- my_array[2][2] = something

it doesn't work ... i don't have find a good example to follow ... so i'm asking to the best and largest comunity of 3d in the world !!!

i've write a fast test where i don't understand the error :

main(doc,op)
{

var x = int(3);
var y = int(3);
var arr=new(array,3,3);
var i ;
var j ;

for (i=0;i<x;i++)
{
for (j=0;j<y;j++)
{
arr[i,j]=0;
}
}

arr[0,1]=3;
arr[2,2]=5;

for (i=0;i<x;i++)
{
for (j=0;j<y;j++)
{
println(arr[i,j]);
}
}
}


thank you very much for your help !!!
any suggestion are welcome !!!

sandidolsak
12-30-2005, 02:06 PM
no errors here with your code...
what error do you get?

0010
12-30-2005, 02:15 PM
Thank you ]angelus[ for your fast reply !!

The error is that if you execute the script and look the console will appear a sequence of 035-035-035 like an array with only 3 rows and no column.

I want to put the value 3 only in the field [0,1] not in the [1,1] and [2,1] fields.

Maybe i mis some basics information to manage with the arrays...

thanks a lot

sandidolsak
12-30-2005, 02:25 PM
Try outputing like this

for (i=0;i<x;i++){
for (j=0;j<y;j++)
print(arr[i,j]);
println();
}

0010
12-30-2005, 02:31 PM
thank you very much ! now the output is better !! but i have the same error :
035
035
035

in my script for putting some value in a field of the array i've write:
arr[0,1]=3;
arr[2,2]=5;

and in my mind the output i want has to be :
030
000
005

but it doesn't work ....

sandidolsak
12-30-2005, 04:37 PM
yap thats really wierd, i made some testing... out of my league i gues :)

JamesMK
12-30-2005, 04:46 PM
Try this instead:


var x = int(3);
var y = int(3);
var arr=new(array,3,3);
var i ;
var j ;

for (i=0;i<x;i++){
for (j=0;j<y;j++) {
arr[i][j]=0;
}
}

arr[0][1]=3;
arr[2][2]=5;

for (i=0;i<x;i++){
for (j=0;j<y;j++) {
print(arr[i][j]);
}
println();
}

0010
12-30-2005, 04:52 PM
WOOOOOW it works !!! it works !!!

thank you very much guys !!!

first step done !!
i've understand my errors now !!

i've to try write something interesting with this language asap !

many thanks again !

0010
01-06-2006, 02:49 PM
Hi all again... :banghead:

i continue here in this tread because i have another question about the array's functions..

Is there a command that delete a row of an array ? (and gets the other rows -1 in row position)

i'm trying to make the Graham's scan for Delaunay Triangulation Algorithm ... :banghead:

any suggestion or code are welcome !!!
thank you very much !!

JamesMK
01-06-2006, 03:01 PM
Is there a command that delete a row of an array ? (and gets the other rows -1 in row position)
There's no such method built into the array datatype (since it's a very bare-bone type) - you'll have to roll your own delete algorithm so to speak.

0010
01-06-2006, 06:24 PM
ok thank you !! ...
i've done something it works now.. !!!

thank you very much for your quick response !

CGTalk Moderation
01-06-2006, 06:24 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.