double mess

hello
I'm new to c++, but I need it to make a dll for game-maker.
now i have this:
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
33
34
35
36
37
38
39
40
41
42
43
#include "dll.h"                                        //Include de header (anders werkt het niet)
#include <windows.h>                                    //Include windows.h, dat moet gewoon
#include <math.h>
export double height(double a,double b){
       double xx,yy,xint,yint,xfrac,yfrac,zz,rcx,rcy;
       double terrain [49][49];
       terrain[1][1]=40;
/*lot of array*/
terrain[49][49]=40;
xx = a/25.6;
yy = b/25.6;
xint = floor(xx);
yint = floor(yy);
xfrac = xx-xint;
yfrac = yy-yint;
if (xint<0) {
xint = 0;
xfrac = 0;
} else if (xint>=50) {
xint = 49;
xfrac = 1;
}
if (yint<0) {
yint = 0;
yfrac = 0;
} else if (yint>=50) {
yint = 49;
yfrac = 1;
}
if (xx>yy) {
rcx = terrain[xint+1][yint]-terrain[xint][yint];
rcy = terrain[xint+1][yint+1]-terrain[xint+1][yint];
} else {
rcx = terrain[xint+1][yint+1]-terrain[xint][yint+1];
rcy = terrain[xint][yint+1]-terrain[xint][yint];
}
zz = terrain[xint][yint]+rcx*xfrac+rcy*yfrac;
return zz;
       }
//PS DLLs die met Game Maker werken kunnen alleen variabelen van het type:
    //double (dat is real in GM)
    //char* (dat is string in GM)
//gebruiken 
as you see, a bit of a mess.
but, that isn't the problem, the problem is this:
32 D:\documenten\WOC\dll\dllmain.cpp invalid types `double[49][49][double]' for array subscript
if I work with onlu int's, it works, but I have to work with double, because else it won't fit in the game.
does anybody has an idea?
Cast explicitly to int inside the brackets. For example: array[(int)a_double_variable]

An array declared as array[n] has elements in the range [0;n-1]. I'm guessing on line 7 and 9 you meant to write [0][0] and [48][48]. If you don't want to fix all your code, you can just add one more row and column to the array, at the expense of memory.
Also, between, on line 8, where you wrote "/*lot of array*/", should I assume that you did something like this?
1
2
3
4
5
6
7
terrain[1][1]=40;
terrain[1][2]=40;
terrain[1][3]=40;
//...
terrain[2][1]=40;
terrain[2][2]=40;
//and so on... 
If so, use loops for god's sake, man!
I'm sorry, but because of I'm dutch and new to c++ I don't understand the first part, but you mean that int array[2] makes array[0] and array[1]?
And the second part, I can't use loops.
The array contains the height of an terrain, so it isn't all 40.
you mean that int array[2] makes array[0] and array[1]?
Yes.

The array contains the height of an terrain, so it isn't all 40.
Use a data file. Anything is preferable to hard-coding the values.
Yes.

I shall edit it to double terrain [50][50];
Use a data file. Anything is preferable to hard-coding the values

Does an header-file succeed?

but, any idea how to transform double to int?
I've solved it.
int (doublename)
Topic archived. No new replies allowed.