Bennu Game Development

English Forums => Helpdesk => Topic started by: MisterN on April 12, 2012, 10:50:08 PM

Title: Game crashes when I delete an object
Post by: MisterN on April 12, 2012, 10:50:08 PM
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.
Title: Re:Game crashes when I delete an object
Post by: l1nk3rn3l on April 14, 2012, 04:15:09 PM
 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
Title: Trying to get values to be fread
Post by: MisterN on April 15, 2012, 05:18:26 PM
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


Title: Re:Game crashes when I delete an object
Post by: handsource-dyko on April 15, 2012, 06:38:20 PM
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).



Title: Re:Game crashes when I delete an object
Post by: MisterN on April 16, 2012, 12:42:56 AM
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
Title: Re:Game crashes when I delete an object
Post by: l1nk3rn3l on April 16, 2012, 02:09:17 PM

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


Title: Re:Game crashes when I delete an object
Post by: handsource-dyko on April 16, 2012, 03:08:16 PM
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. :(


Title: Re:Game crashes when I delete an object
Post by: MisterN on April 16, 2012, 09:04:37 PM
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
Title: Re:Game crashes when I delete an object
Post by: MisterN on April 17, 2012, 03:32:16 AM
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

Title: Can you go fullscreen without changing resolution?
Post by: MisterN on April 19, 2012, 11:27:25 PM
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.
Title: Re:Game crashes when I delete an object
Post by: handsource-dyko on April 20, 2012, 07:24:15 AM
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 (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.
Title: Re:Game crashes when I delete an object
Post by: MisterN on April 20, 2012, 02:41:30 PM
But that changes the resolution of the monitor. I was just wondering if theres a way for it to be fullscreen without doing so.
Title: Re:Game crashes when I delete an object
Post by: handsource-dyko on April 20, 2012, 04:44:36 PM
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).
Title: Re:Game crashes when I delete an object
Post by: MisterN on April 28, 2012, 10:08:22 PM
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?
Title: Re:Game crashes when I delete an object
Post by: handsource-dyko on April 29, 2012, 09:06:52 AM
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.







Title: Re:Game crashes when I delete an object
Post by: MisterN on April 29, 2012, 04:51:55 PM
I tried both of those and they dont work  :'( ill keep trying some more tactics today

If I do >4 it works somehow
Title: Some more .txt reading help
Post by: MisterN on May 09, 2012, 09:59:25 PM
This works for getting numbers for variables

///////////////////////////////////////////
//////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 MAX_ENE_C 25    // maximum enemy objects available

#define SCR_DEPTH    16


GLOBAL
    option;
    string1,string2;
    handle;

    INCLUDE "level_struct.prg";
END
   
BEGIN
    handle = fopen("level_information.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


but I need to do one more thing. I want to make a string3, and line 3 in my .txt file is "example.lev". How will I be able to get level.filename to get its name from a .txt file? thanks
Title: Re:Game crashes when I delete an object
Post by: handsource-dyko on May 10, 2012, 07:07:49 AM
Simple. Use fgets. A filename is already a string and therefore there's no conversion needed. I recommend however, to check if the string is a valid (existing) filename by using the fexists function.

I.e.


string3= fgets(handle);

IF (fexists(string3) == FALSE)

    // error
    say("error! file does not exist");

   // do some more stuff, i.e. quit the program ask user for different filename, etc, etc, whatever you like.
ELSE

   // filename is ok, do nothing
END

Title: Re:Game crashes when I delete an object
Post by: MisterN on May 10, 2012, 12:42:57 PM
.txt file
Quote
"example.lev"
3120
240

code
///////////////////////////////////////////
//////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 MAX_ENE_C 25    // maximum enemy objects available

#define SCR_DEPTH    16


GLOBAL
    option;
    string1,string2,string3;
    handle;

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

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


    fclose(handle);

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


END










does not work
Title: Re:Game crashes when I delete an object
Post by: FreeYourMind on May 10, 2012, 01:46:42 PM
what this ?

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

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


    fclose(handle);

this is not correct....
Title: How to attract an object
Post by: MisterN on May 11, 2012, 04:36:23 AM
I got the code to work done worry lol. Now I am wondering, how can I have an object gravitate towards another object. direction and collisions do not matter for this case. I am making a "boomerang" like weapon that after a certain amount of time, will come back to the player. I simply need some code to have it move towards the player. thanks
Title: Re:Game crashes when I delete an object
Post by: handsource-dyko on May 12, 2012, 08:58:48 AM
Maybe with fget_dist and fget_angle ? http://wiki.bennugd.org/index.php?title=Fget_dist (http://wiki.bennugd.org/index.php?title=Fget_dist)
But it may probably be done simpler.
Title: Re:How to attract an object
Post by: MisterN on May 19, 2012, 03:29:38 PM
I dont see how that would move towards a process
Title: Re:Game crashes when I delete an object
Post by: l1nk3rn3l on May 19, 2012, 03:45:11 PM
 ;D

BENNUPACK INCLUDES A LOT EXAMPLES ..

maybe usefull too
Title: Re:Game crashes when I delete an object
Post by: MisterN on May 19, 2012, 09:27:06 PM
couldnt find anything