Bennu Game Development

English Forums => Helpdesk => Topic started by: aliasbody on July 17, 2014, 10:35:01 AM

Title: Call 2D Array in a Function doesn't work or provide a strange number
Post by: aliasbody on July 17, 2014, 10:35:01 AM
Hello Everyone,

So here is my problem. I created a 2D Array containing the informations for my map to be shown, and then I created a function that would take that array and turn it into something we can see in the screen.

Now the problem is, if I use a "normal" way of handling the 2D Array in this function, then I either won't be able to compile or I will have a Segmentation Fault. If I use a "type" just for it then the numbers I have have 7 digits of Zero (0) just before the number I need. And I don't know how to solve this problem.

Here is the actual code which gives me the 7 zeros :


Import "mod_say" ;
Import "mod_map"    ;
Import "mod_key"    ;
Import "mod_video"  ;
Import "mod_screen" ;

Const
    MODE_X = 640;
    MODE_Y = 480;

TILE_Y = 32;
TILE_X = 24;

SPRITE_SIZE = 20;
End

type levels
End

Global
    int map, i, j;

_levels Level1[TILE_X-1][TILE_Y-1] = 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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X, MODE_Y, MODE_16BITS);
    set_fps(30,0);

map = map_new(SPRITE_SIZE, SPRITE_SIZE, MODE_16BITS);

loadTilesMap(&Level1);

Repeat
frame;
Until (Key(_esc))
End

Process loadTilesMap(levels **myArray)
Begin
say(myArray[0][0]);
For (i = 1; i <= TILE_X; i++)
For (j = 1; j <= TILE_Y; j++);
Switch (myArray[i-1][j-1])
Case 1:
map_clear(0, map, rgb(100, 100, 100));
End

Case 2:
map_clear(0, map, rgb(255, 255, 255));
End
End

put(0, map, (j*SPRITE_SIZE)-(SPRITE_SIZE/2), (i*SPRITE_SIZE)-(SPRITE_SIZE/2));
End
End
End


Before having this function I had the 2D Array declared like this :

int Level1[TILE_X-1][TILE_Y-1] = .....

Thanks in Advance for any help.
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: SplinterGU on July 17, 2014, 11:52:17 AM
type levels
End

void???
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: aliasbody on July 17, 2014, 12:25:35 PM
Quote from: SplinterGU on July 17, 2014, 11:52:17 AM
type levels
End

void???

It was just a try :S Originaly I wasn't using "type" because I didn't need it, I just tested and let it that way just to show that, that way, I have some results but they are incorrect. But still I don't know how to solve this.
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: SplinterGU on July 17, 2014, 12:38:52 PM
the function don't know the array dimensions... try this


Const
    MODE_X = 640;
    MODE_Y = 480;

    TILE_X = 32;
    TILE_Y = 24;

    SPRITE_SIZE = 20;
End

declare Process loadTilesMap(int *myArray)
end

Global
    int map, i, j;

    int Level1[TILE_Y-1][TILE_X-1]  =
                            2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
                            1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,
                            1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,
                            1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2;
    enemy enemy;
    final final;
Begin
    set_mode(MODE_X, MODE_Y, MODE_16BITS);
    set_fps(30,0);

    map = map_new(SPRITE_SIZE, SPRITE_SIZE, MODE_16BITS);

    loadTilesMap(&Level1);

    Repeat
        frame;
    Until (Key(_esc))
End

Process loadTilesMap(int *myArray)
Begin
    For (i = 0; i < TILE_Y; i++)
        For (j = 0; j < TILE_X; j++);
            Switch (myArray[i*TILE_X+j])
                Case 1:
                    map_clear(0, map, rgb(100, 100, 100));
                End

                Case 2:
                    map_clear(0, map, rgb(255, 255, 255));
                End
            End
            put(0, map, (j*SPRITE_SIZE)-(SPRITE_SIZE/2), (i*SPRITE_SIZE)-(SPRITE_SIZE/2));
        End
    End
End
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: aliasbody on July 17, 2014, 01:31:46 PM
Quote from: SplinterGU on July 17, 2014, 12:38:52 PM
the function don't know the array dimensions... try this


Const
    MODE_X = 640;
    MODE_Y = 480;

    TILE_X = 32;
    TILE_Y = 24;

    SPRITE_SIZE = 20;
End

declare Process loadTilesMap(int *myArray)
end

Global
    int map, i, j;

    int Level1[TILE_Y-1][TILE_X-1]  =
                            2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
                            1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,
                            1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,
                            1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2;
    enemy enemy;
    final final;
Begin
    set_mode(MODE_X, MODE_Y, MODE_16BITS);
    set_fps(30,0);

    map = map_new(SPRITE_SIZE, SPRITE_SIZE, MODE_16BITS);

    loadTilesMap(&Level1);

    Repeat
        frame;
    Until (Key(_esc))
End

Process loadTilesMap(int *myArray)
Begin
    For (i = 0; i < TILE_Y; i++)
        For (j = 0; j < TILE_X; j++);
            Switch (myArray[i*TILE_X+j])
                Case 1:
                    map_clear(0, map, rgb(100, 100, 100));
                End

                Case 2:
                    map_clear(0, map, rgb(255, 255, 255));
                End
            End
            put(0, map, (j*SPRITE_SIZE)-(SPRITE_SIZE/2), (i*SPRITE_SIZE)-(SPRITE_SIZE/2));
        End
    End
End


Thank you for the suggestion !
It works because it shows values but it doesn't work because the calculation is wrong. So if I get it right I can only point for one and then I would have to get the values. In this calculation the array has 768 values devided by 32 columns and 24 rows (virtually of course), so if I want the first value I need to do myArray[0] instead of myArray[0][0], and in order to have the last value I need to do myArray[768] instead of myArray[23][31].

Isn't there a way to do it with
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: aliasbody on July 17, 2014, 02:31:01 PM
This is what I needed to change in order to make it work :

For (i = 0; i < TILE_X; i++)
For (j = 0; j < TILE_Y; j++);
Switch(a[i*TILE_Y+j])

Now I only need to understand why the first row and the first column of the tiles are misplaced
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: aliasbody on July 17, 2014, 02:34:02 PM
Solved !  ;D

This is the final code

Import "mod_say" ;
Import "mod_map"    ;
Import "mod_key"    ;
Import "mod_video"  ;
Import "mod_screen" ;

Const
    MODE_X = 640;
    MODE_Y = 480;

TILE_Y = 32;
TILE_X = 24;

SPRITE_SIZE = 20;
End

Global
    int map, i, j;

int Level1[TILE_X-1][TILE_Y-1] = 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1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PRITE_SIZE, MODE_16BITS);

loadTilesMap(&Level1);

Repeat
frame;
Until (Key(_esc))

End

Process loadTilesMap(int *a)
Begin

For (i = 0; i < TILE_X; i++)
For (j = 0; j < TILE_Y; j++);
Switch(a[i*TILE_Y+j])
Case 1:
map_clear(0, map, rgb(100, 100, 100));
End

Case 2:
map_clear(0, map, rgb(255, 255, 255));
End
End

put(0, map, (j*SPRITE_SIZE)+(SPRITE_SIZE/2), (i*SPRITE_SIZE)+(SPRITE_SIZE/2));
End
End
End


Thank you SplinterGU ! You are the best ;) !

Just one question, in the version you've posted you used :


declare Process loadTilesMap(int *myArray)
end


In my version I didn't used it and it worked as well. What does the "Declare" does in difference from the method I made ?
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: SplinterGU on July 17, 2014, 06:13:02 PM
no, no...

the arrays are

[ y ][ x ]

y elements, with x columns

the bad was

         put(0, map, (j*SPRITE_SIZE)+(SPRITE_SIZE/2), (i*SPRITE_SIZE)+(SPRITE_SIZE/2));

this is

put(file,map, x, y)

how I wrote works... but I don't use put, I only print with say the content of array in the code...

you run

->
and then you down to the next line
|
v

and then

-> again



Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: SplinterGU on July 17, 2014, 06:34:10 PM
this works prefect


Import "mod_say"    ;
Import "mod_map"    ;
Import "mod_input"  ;
Import "mod_video"  ;

Const
    MODE_X = 640;
    MODE_Y = 480;

    TILE_X = 32;
    TILE_Y = 24;

    SPRITE_SIZE = 20;
End

type levels
End

process tile(graph, x, y)
Begin
    while(!key(_ESC))
        frame;
    end
end

declare Process loadTilesMap(int *myArray)
end

Global
    int map, i, j;

    int Level1[TILE_Y-1][TILE_X-1]  =
                            2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
                            1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,
                            1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,
                            1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2;
    enemy enemy;
    final final;
    map1, map2;
Begin
    set_mode(MODE_X, MODE_Y);
    set_fps(30,0);


    map1 = map_load("map1.png");
    map2 = map_load("map2.png");

    loadTilesMap(&Level1);

//    Repeat
//        frame;
//    Until (Key(_esc))
End

Process loadTilesMap(int *myArray)
Begin
    For (i = 0; i < TILE_Y; i++)
        For (j = 0; j < TILE_X; j++);
            Switch (myArray[i*TILE_X+j])
                Case 1:
                    tile(map1,j*SPRITE_SIZE+SPRITE_SIZE/2, i*SPRITE_SIZE+SPRITE_SIZE/2);
                End

                Case 2:
                    tile(map2,j*SPRITE_SIZE+SPRITE_SIZE/2, i*SPRITE_SIZE+SPRITE_SIZE/2);
                End
            End

        End
    End
End


capture

(http://forum.bennugd.org/index.php?action=dlattach;topic=3911.0;attach=3190)
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: aliasbody on July 17, 2014, 07:32:22 PM
Quote from: SplinterGU on July 17, 2014, 06:34:10 PM
this works prefect


Import "mod_say"    ;
Import "mod_map"    ;
Import "mod_input"  ;
Import "mod_video"  ;

Const
    MODE_X = 640;
    MODE_Y = 480;

    TILE_X = 32;
    TILE_Y = 24;

    SPRITE_SIZE = 20;
End

type levels
End

process tile(graph, x, y)
Begin
    while(!key(_ESC))
        frame;
    end
end

declare Process loadTilesMap(int *myArray)
end

Global
    int map, i, j;

    int Level1[TILE_Y-1][TILE_X-1]  =
                            2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
                            1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,
                            1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,
                            1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                            2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2;
    enemy enemy;
    final final;
    map1, map2;
Begin
    set_mode(MODE_X, MODE_Y);
    set_fps(30,0);


    map1 = map_load("map1.png");
    map2 = map_load("map2.png");

    loadTilesMap(&Level1);

//    Repeat
//        frame;
//    Until (Key(_esc))
End

Process loadTilesMap(int *myArray)
Begin
    For (i = 0; i < TILE_Y; i++)
        For (j = 0; j < TILE_X; j++);
            Switch (myArray[i*TILE_X+j])
                Case 1:
                    tile(map1,j*SPRITE_SIZE+SPRITE_SIZE/2, i*SPRITE_SIZE+SPRITE_SIZE/2);
                End

                Case 2:
                    tile(map2,j*SPRITE_SIZE+SPRITE_SIZE/2, i*SPRITE_SIZE+SPRITE_SIZE/2);
                End
            End

        End
    End
End


capture

(http://forum.bennugd.org/index.php?action=dlattach;topic=3911.0;attach=3190)

Thank you ! My method was working because I had manage to solve the problem even using inverted values, I made the mistake the inverting the Y and the X of the array. I've updated my code and start using your method, and now it works perfectly ! (just one question, why do you have a pixel of black line on the left and on the right ? I didn't see the size of the map.png you've sent but could it be that ?)

Anyway, thank you a lot for this help :) I will upload it into the projects page as the v0.3 of the BennuCube. It is alwasy great to have some quick and small examples for anyone trying to learn BennuGD.
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: SplinterGU on July 17, 2014, 07:37:19 PM
I'm using a new bennugd version.. with GPU acceleration... maybe I have some problem in it...

I don't know... I don't have the old version anymore...
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: aliasbody on July 17, 2014, 07:47:00 PM
Quote from: SplinterGU on July 17, 2014, 07:37:19 PM
I'm using a new bennugd version.. with GPU acceleration... maybe I have some problem in it...

I don't know... I don't have the old version anymore...

The new version ? BennuGD 2 or an other derivate ?
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: FreeYourMind on July 17, 2014, 08:44:37 PM
feel the rat troll  ::)
Title: Re:Call 2D Array in a Function doesn't work or provide a strange number
Post by: SplinterGU on July 18, 2014, 02:17:19 AM
Quote from: aliasbody on July 17, 2014, 07:47:00 PM
Quote from: SplinterGU on July 17, 2014, 07:37:19 PM
I'm using a new bennugd version.. with GPU acceleration... maybe I have some problem in it...

I don't know... I don't have the old version anymore...

The new version ? BennuGD 2 or an other derivate ?

yes, it will be...