|
2 registered members (3run, AndrewAMD),
623
guests, and 1
spider. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
problem with arrays (part 2)
#345138
10/23/10 15:08
10/23/10 15:08
|
Joined: Oct 2010
Posts: 5
maddoctor
OP
Newbie
|
OP
Newbie
Joined: Oct 2010
Posts: 5
|
And here I thought that only strings have problems when used in arrays. http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=345108&#Post345108Now I experience problems with vectors too. What's the difference between the following lines of code: 1: (coordinates given directly)
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)
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
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)
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
Last edited by maddoctor; 10/23/10 15:21.
|
|
|
|