Page 1 of 1

How can I use this--> STRUCT ?

PostPosted: Fri Mar 06, 2009 5:17 pm
by equinox
struct character {
char *name;
Actor* actor;
int hp;
int mp;
} heroes[2] = { {"hero one\0", 0, 10, 10}, {"hero two\0", 0, 5, 15} };


...Now how do I create a hero one....ecc?

Tnk1000 for help.

Re: How can I use this--> STRUCT ?

PostPosted: Fri Mar 06, 2009 8:16 pm
by makslane
What you want to do with this struct?

Re: How can I use this--> STRUCT ?

PostPosted: Sat Mar 07, 2009 1:12 am
by skydereign
If I understand what you are trying to do, create a player struct, then I would do a typedef and then create an array of struct pointers. I believe you only need one type of struct for your hero and let's just say enemies. The actor would have internal values that tell it which struct it is, an example being cloneindex. All of this can get a little tricky if you want to make the players on the go, as you would need to set up a realloc system. But if you know how many structs you need, then creating a struct pointer array can accomplish what you want. I would do this in the create actor for view, as it is the first actor related event.
view->CreateActor->Script Editor
Code: Select all
int i;
int j;
for (i = 0; i > 2; i++)
{
    for (j = 0; j > 5; j++)
    {
        charArray[i][j]=character_create();
    }
}

As you can tell, this needs a function called character_create, which would go into global code.
GlobalCode
Code: Select all
character_t *
character_create (void)
{
    character_t * self = calloc(1, sizeof(character_t));
    return(self);
}

This also requires a struct character_t, and more.
Note you need to create charArray[][], which is a struct * array. I can go more in depth or make a demo if need be, this is a bit circumstantial... I hope this cleared things up more than not, or at least pointed you in the right direction.

Re: How can I use this--> STRUCT ?

PostPosted: Sat Mar 07, 2009 8:15 am
by equinox
HI,

You were very kind to explain.

If you can, please, to make myself a exmple, so I can study and understand better.

Tnk1000.

score += 1...for moment..

This code is your:
I can not understand how to use it to create "ACTOR/SPRITE" and read / write variables for ex: HERO HERO :0-.1 ..... EROE.n

struct actorName
{
double x;
double y;
char[] name;
char[] clonename;
int cloneindex;
int height;
int width;
int animindex;
int animpos;
int nframes;
int transp;
int r;
int g;
int b;
double directional_velocity;
double angle;
double xvelocity;
double yvelocity;
double xscreen;
double yscreenl
double xprevious;
double yprevious;
// And many many more.... The ones you create as actor variables appear
// Not sure on all the types but I think they are right
}

Re: How can I use this--> STRUCT ?

PostPosted: Sun Mar 08, 2009 11:04 am
by skydereign
Okay, it sounds like you are trying to create your own actor... What I am doing is to create structs out in memory. Essentially an array of them, to use a struct you would need a handle. So I use a function that creates a struct and hands back a pointer to the struct. Each actor has its own internal values, such as cloneindex. I use cloneindex, along with the character type, HERO being 0, ENEMY being 1. With these values, they are plugged into the array, and I now have a pointer to the struct, allowing me to manipulate the struct. Because hero and enemy are closely related, I kept the same struct, and organized them into an array. If I am not making any sense just say so. Here is a demo of what I am talking about, maybe that will make more sense.