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

#15
I tried both of those and they dont work  :'( ill keep trying some more tactics today

If I do >4 it works somehow
werg

MisterN

#16
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
werg

handsource-dyko

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


MisterN

.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
werg

FreeYourMind

what this ?

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

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


    fclose(handle);

this is not correct....

MisterN

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
werg

handsource-dyko

Maybe with fget_dist and fget_angle ? http://wiki.bennugd.org/index.php?title=Fget_dist
But it may probably be done simpler.

MisterN

I dont see how that would move towards a process
werg

l1nk3rn3l

 ;D

BENNUPACK INCLUDES A LOT EXAMPLES ..

maybe usefull too

MisterN

werg