Game crashes when I delete an object

Started by MisterN, April 12, 2012, 10:50:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MisterN

notepad++ cannot run the game in debugmode correctly, idk why, but I really need it to see whats going on. But if someone would be kind enough to show me, that would be good too. On my level editor, when you press alt (to remove an object/tile), the game crashes. I do not know why it is doing this and I do not have an older version of this to look at. Thanks

more information:
the alt key will be in main_leveleditor.prg, in the block_placement process, from lines 625 to 681.
werg

l1nk3rn3l

 8)




not is notepad++ problem ,  please test your games , in a ...BAT file .. with this



bgdc.exe game_leveleditor.prg
bgdi.exe game_leveleditor.dcb
pause




and press alt




possibly is a access memory error since your code..


please check access a pointers o arrays.. or identifiers

MisterN

Here is the code:

///////////////////////////////////////////
//////A simple level data compiler/////////
//////For use with the Annihila-Co/////////
/////////////Platform Engine///////////////
///////////////////////////////////////////

IMPORT "mod_debug";
IMPORT "mod_dir";
IMPORT "mod_file";
IMPORT "mod_key";
IMPORT "mod_map";
IMPORT "mod_text";
IMPORT "mod_screen";
IMPORT "mod_scroll";
IMPORT "mod_draw";
IMPORT "mod_say";
IMPORT "mod_string";
IMPORT "mod_proc";
IMPORT "mod_grproc";
IMPORT "mod_video";
IMPORT "mod_wm";
IMPORT "mod_sys";
IMPORT "mod_joy";
IMPORT "mod_math";
IMPORT "mod_rand";
IMPORT "mod_sound";
IMPORT "mod_time";
IMPORT "mod_timers";
IMPORT "mod_cd";

#define TILE_DIMX 195
#define TILE_DIMY 15
 
#define MAX_COL    255    // maximum collectible objects available
#define MAX_ENE_A 25    // maximum enemy objects available
#define MAX_ENE_B 25    // maximum enemy objects available


TYPE t_tile;

    bool used;
    byte kind;
END

GLOBAL

INCLUDE "level_struct.prg";

END

PROCESS main();

BEGIN

    set_mode(320,240,16);
    set_fps(0,0); //do the placer being the only thing that moves, the framerate can be lowered
   
    //the title in the window
    set_title("level data compiler");
   
    // create some initial (default) data
    load_level_width("level_width.txt");
    load_level_height("level_height.txt");
    //level.width=3120;
    //level.height=240;
   
    // save a level
        say("level data saved");
        save("level.data",level);
   
    IF (key(_esc) or exit_status)
        exit("goodbye!",0);
    END
   
END

process load_level_width(STRING loadpath);
private
    int handle;   // handle for the loaded file
begin

    handle=fopen(loadpath,O_READ); // opens the file in reading mode
    fread(handle,level.width);        // reads from the file and puts the data in level.width
    fclose(handle);                // zipping up after business is done

end

process load_level_height(STRING loadpath);
private
    int handle;   // handle for the loaded file
begin

    handle=fopen(loadpath,O_READ); // opens the file in reading mode
    fread(handle,level.height);        // reads from the file and puts the data in level.height
    fclose(handle);                // zipping up after business is done

end


I am trying to make a program that will create a .data file for my level editor (such as the levels name, the width, and the height). And it reads the information from .txt files at the moment. level_width.txt and level_height.txt. level_width.txt just says 3120 and level_height.txt just says 240. Am I doing the fread thing right? Cause its not working. Thanks


werg

handsource-dyko

you need the fgets() function to read ascii data from a file, not fread. Fread() is for binary data. Why are you using two files? You can combine both in one txt file, fgets() reads one line, but on the next call it reads the next line (just on line at a time).

To read this text file:



line 1
line 2
line 3
line 4


you need 4 fgets after each other.


handle = fopen("filename.txt", O_READ);

string1 = fgets(handle);
string2 = fgets(handle);
string3 = fgets(handle);
string4 = fgets(handle);

fclose(handle);


If you have very long files, you might want to use a loop. Also since you're reading nummerical data from a string, you
have to convert the string to an integer, with the atoi() function, i.e. number1 = atoi(string1); The atoi function returns some
error status if the string is invalid (contains non-nummerical characters).




MisterN

#4
line 1
line 2
line 3
line 4


doesnt work in the game... and this doesnt either,

level.width=fgets(handle);
level.height=fgets(handle);


so i dont know what to put in :l
werg

l1nk3rn3l


please use atoi to convert string to INteger











// --------------------------------------------------------------------------
// Bennu Tests                                         2000 José Luis Cebrián
// --------------------------------------------------------------------------


#ifndef __VERSION__
    import "mod_sdlevthandler";
    import "mod_pathfind";
#else
    import "mod_blendop";
    import "mod_text";
    import "mod_grproc";
    import "mod_video";
    import "mod_map";
    import "mod_screen";
    import "mod_path";
    import "mod_rand";
    import "mod_say";
    import "mod_mouse";
    import "mod_scroll";
    import "mod_math";
#endif


import "mod_m7";
import "mod_proc";
import "mod_key";
import "mod_draw";
import "mod_timers";
import "mod_sound";
import "mod_file";
import "mod_string"


#define SCR_DEPTH   16


GLOBAL
  option ;
  string1,string2,string3;
  handle;






BEGIN
   handle = fopen("filename.txt", O_READ);


   string1 = fgets(handle);
   string2 = fgets(handle);
   string3 = fgets(handle); 


   fclose(handle);


   x= atoi(string1); //convert string to INTeger
   y= atoi(string2);
   z= atoi(string3);
   


    set_mode(320,200,SCR_DEPTH);
       
    write (0, 160,  10, 1, "value 1  " + x) ;
write (0, 160,  20, 1, "value 2  " + y) ;
write (0, 160,  30, 1, "value 3  " + z) ; 
   
    REPEAT
   
        FRAME ;
    UNTIL key(_esc);


END



handsource-dyko

Duh!  :o The four lines


line 1
line 2
line 3
line 4


are a txt file, not actual program code. I'd thought you'd know. :(



MisterN

#7
That wasnt very clear lol but anyways ill try this out when i get home.

EDIT: still doesn't work

///////////////////////////////////////////
//////A simple level data compiler/////////
//////For use with the Annihila-Co/////////
/////////////Platform Engine///////////////
///////////////////////////////////////////

IMPORT "mod_debug";
IMPORT "mod_dir";
IMPORT "mod_file";
IMPORT "mod_key";
IMPORT "mod_map";
IMPORT "mod_text";
IMPORT "mod_screen";
IMPORT "mod_scroll";
IMPORT "mod_draw";
IMPORT "mod_say";
IMPORT "mod_string";
IMPORT "mod_proc";
IMPORT "mod_grproc";
IMPORT "mod_video";
IMPORT "mod_wm";
IMPORT "mod_sys";
IMPORT "mod_joy";
IMPORT "mod_math";
IMPORT "mod_rand";
IMPORT "mod_sound";
IMPORT "mod_time";
IMPORT "mod_timers";
IMPORT "mod_cd";

#define TILE_DIMX 195
#define TILE_DIMY 15
 
#define MAX_COL    255    // maximum collectible objects available
#define MAX_ENE_A 25    // maximum enemy objects available
#define MAX_ENE_B 25    // maximum enemy objects available


TYPE t_tile;

    bool used;
    byte kind;
END

GLOBAL

    option;
        string1,string2;
    handle;

INCLUDE "level_struct.prg";

END

PROCESS main();

BEGIN
    //the title in the window
    set_title("level data compiler");
   
    // create some initial (default) data
    handle=fopen("level_data.txt",O_READ); // opens the file in reading mode
   
    string1=fgets(handle);
    string2=fgets(handle);
   
    fclose(handle);                // zipping up after business is done
   
    level.width=atoi(string1);
    level.height=atoi(string2);
   
    // save a level
        save("level.data",level);
        say("level data saved");
    //display the level data
        say("level.width:"+level.width);
        say("level.height:"+level.height);
   
    IF (key(_esc) or exit_status)
        exit("goodbye!",0);
    END
   
END
werg

MisterN

this works though

///////////////////////////////////////////
//////A simple level data compiler/////////
//////For use with the Annihila-Co/////////
/////////////Platform Engine///////////////
///////////////////////////////////////////

#ifndef __VERSION__
    import "mod_sdlevthandler";
    import "mod_pathfind";
#else
    import "mod_blendop";
    import "mod_text";
    import "mod_grproc";
    import "mod_video";
    import "mod_map";
    import "mod_screen";
    import "mod_path";
    import "mod_rand";
    import "mod_say";
    import "mod_mouse";
    import "mod_scroll";
    import "mod_math";
#endif


import "mod_m7";
import "mod_proc";
import "mod_key";
import "mod_draw";
import "mod_timers";
import "mod_sound";
import "mod_file";
import "mod_string"

#define TILE_DIMX 195
#define TILE_DIMY 15
 
#define MAX_COL    255    // maximum collectible objects available
#define MAX_ENE_A 25    // maximum enemy objects available
#define MAX_ENE_B 25    // maximum enemy objects available


#define SCR_DEPTH    16


GLOBAL
    option;
    string1,string2;
    handle;

    INCLUDE "level_struct.prg";
END
   
BEGIN
    handle = fopen("filename.txt", O_READ);


    string1 = fgets(handle);
    string2 = fgets(handle);


    fclose(handle);


    level.width= atoi(string1);
    level.height= atoi(string2);
   
    save("level.data",level);
    say("level data saved");
       
    say ("level width: " + level.width) ;
    say ("level height: " + level.height) ;


END

werg

MisterN

I was wondering if there is a way to go fullscreen without changing the resolution of the computer. It would still be sharp looking and in the correct aspect ratio I would assume? Im just asking because Game Maker has something similar to this.
werg

handsource-dyko

Simple. Simply set full_screen to "true"and call set_mode again. This also applies for the scale_mode. However, it doesn't scale by itself, so 320x240 full screen looks pixelated therefore I also recommend using on of the http://wiki.bennugd.org/index.php?title=Scale_modes.

You can only scale something with a factor of 2. Malvado uses 320x200 with a scaler to make it 640x400.

MisterN

But that changes the resolution of the monitor. I was just wondering if theres a way for it to be fullscreen without doing so.
werg

handsource-dyko

Nope.  :( If you do full screen it won't do any scaling. Do you mean a window resize? I.e. a window as big as the monitor resolution? In that case you have to use set mode. Bennu does not have any automatic scaling, it only supports scaling by 2, and offers the filters as mentioned on the wiki. It would be nice to have a 3x or a 4x scaler though, I don't know if that's a lot of work to implement or if SDL supports that.  (It would be a good feature suggestion).

MisterN

When you go fullscreen in a game, it adjusts the resolution of the monitor (ex. your game in fullscreen at maximum is 1280x720 but your monitor is 1440x1080, so your monitors resolution has been re-adjusted).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now, I have a bunch of tiles that are used for collision, but so I can save time on code, I tried to do
level.tile[(x-player.dimx/2)/block_size][y/block_size].kind==5..16
like you can with case, but that doesnt work. So what can I do?
werg

handsource-dyko

#14
Sorry, no can do. You'd have to check with if or case statements. There's no shortcut here. However, you could check for a range by using OR statements. E.i:


IF (level.tile[(x-player.dimx/2)/block_size][y/block_size].kind > 5 AND level.tile[(x-player.dimx/2)/block_size][y/block_size].kind < 16)
END


etc etc. I'm not sure if it can be written like this (in mathematic form):


IF ( level.tile[(x-player.dimx/2)/block_size][y/block_size].kind > 5 < 16)
END


Probably doesn't work, you have to experiment, but the first form should work, but is a lot of typing.