problem with arrays (part 2)

Posted By: maddoctor

problem with arrays (part 2) - 10/23/10 15:08

And here I thought that only strings have problems when used in arrays.
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=345108&#Post345108

Now I experience problems with vectors too.
What's the difference between the following lines of code:

1: (coordinates given directly)
Code:
while(1) {   
draw_line(vector(x1,y1,0),NULL,100);
draw_line(vector(x2,y1,0),vector(0,0,255),100);
draw_line(vector(x2,y2,0),vector(0,0,255),100);	draw_line(vector(x1,y2,0),vector(0,0,255),100);	draw_line(vector(x1,y1,0),vector(0,0,255),100);
wait(1);  
 }



2: coordinates in an array (of course I initialize all array contents first: coordinates[0] = vector(x1,y1,0), coordinates[1] = vector(x2,y1,0) etc etc)
Code:
while (1){
draw_line(coordinates[0],NULL,100); 
draw_line(coordinates[1],vector(0,0,255),100);
draw_line(coordinates[2],vector(0,0,255),100);
draw_line(coordinates[3],vector(0,0,255),100);
draw_line(coordinates[4],vector(0,0,255),100);
wait(1);
}



3. 5 different variables containing the same coordinates as above
Code:
while (1){
draw_line(coordinates1,NULL,100); 
draw_line(coordinates2,vector(0,0,255),100);
draw_line(coordinates3,vector(0,0,255),100);
draw_line(coordinates4,vector(0,0,255),100);
draw_line(coordinates5,vector(0,0,255),100);
wait(1);
}



4. recreating the vectors from the above variables (in 3)
Code:
while (1){
draw_line(vector(coordinates1.x,coordinates1.y, 0),NULL,100);
draw_line(vector(coordinates2.x,coordinates2.y, 0),vector(0,0,255),100);
draw_line(vector(coordinates3.x,coordinates3.y, 0),vector(0,0,255),100);
draw_line(vector(coordinates4.x,coordinates4.y, 0),vector(0,0,255),100);
draw_line(vector(coordinates5.x,coordinates5.y, 0),vector(0,0,255),100);
wait(1);
}



All 4 of them should give the same results, correct? However the first one works properly but the others draw the line only for one frame (they appear and then disappear after a few seconds)
I want to use the array option (2) since I want to create a "drawing" application/game were the player will move a cursor to draw lines and I want the array to store the coordinates of all the different positions the player passed through.

The array is created with this command:
VECTOR* coordinates[100];
and the 5 variables:
VECTOR* coordinates1;
VECTOR* coordiantes2;
etc etc
Posted By: muffel

Re: problem with arrays (part 2) - 10/23/10 16:02

I think filling the array is here the problem. perhaps this helps:
-Make array of normal vectors(no pointers)
-fill it with using vec_set

Reason why yours with pointers can't work. vector() creates an temporary vector after sometime its get overwritten

muffel
© 2023 lite-C Forums