place an object to be saved in a structure?

Started by MisterN, February 06, 2012, 04:37:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MisterN

Now that im content with knowing everything else I need. I still need help placing an object to be saved in the structure. What I mean is, I want to make a program with a moving cursor, I can place something where that cursor is currently at. That is easy but I cannot get a structure to save into or load from. This is all the structure code I have

struct level
    //Level based stuff
        //Top left hand corner dimmensions (set to 0)
            topx = 0; topy = 0;
        //Bottom right hand corner dimmensions (are changed based on level)
            botx; boty;
        //Background image
            background_image;
   
    //Player based
    playerx; playery; //the current coordinates of the player, they are not in the player sturcture
                      //because they are loaded with the level
end

struct player
    //Transparency (0 - invisible, 100 - fully visible)
        alpha = 0;
    //Information
        dimx = 9;
        dimy = 30;
    //Status
        walking=false;
        jumping=false;
        falling=false;
    //Movement
        walk_speed = 1;
        jump_speed = 2;
            apex = 0;
            apex_reached = 32;
        fall_speed = 2;
    //Animation
        i = 2;
        animation_timer = 9;
        time = 1;
end

type _block
    int x;
    int y;
end


Im not sure if type _block is a correct thing to do (maybe you can clarify on that one) nor do I know how to use it in this instance. I know I can do block
  • , but still, I dont know how to use it (someone told me to do block
  • = block(); but that does not work and that is too tedious).

    Basically, how can I place an object in the game itself, save it, and have it load? thanks
werg

Arcontus

I recomend you look "type struct" for you code. To do this you only need 3 steps:
1- declare a type name for this struct:

type scrol;
    sx;
    sy;
    cam;
end


2- declare a variable type of the struct, it can be global, private or local:

GLOBAL
scrol myScrol;
scrol myScrol2;
END


3- You can access to these structs by nameVar.structVar:
myScrol.sx = 15;
myScrol2.sx = 34;


Well, if you want to create a struct with parameters of a process you can do it that way.

Regards!

5Leaps, el primer juego comercial desarrollado para BennuGD. http://www.5leaps.com