Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/19/24 18:45
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, 7th_zorro, TedMar, Ayumi), 800 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
entitys and structures #113216
02/22/07 10:09
02/22/07 10:09
Joined: Sep 2003
Posts: 407
inside to my
er_willy Offline OP
Senior Member
er_willy  Offline OP
Senior Member

Joined: Sep 2003
Posts: 407
inside to my
Any know some mode for what one entity pointer and one structure using the same name/pointer. Is it possible?

crapy example:
typedef struct
{
int height;
int weigh;
char name;
......
}PLAYERS;

PLAYERS* player_01_stru;

ENTITY* player_01_ent;

//unknow code what make it, what player_01_stru and player_01_ent become
//in player_01 and can us make this:

player_01.pan = 90
player_01.weigh = 45;

Re: entitys and structures [Re: er_willy] #113217
02/22/07 10:39
02/22/07 10:39
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
I don't think that's possible.

You could, however, put an entity in the struct and refer to it like this:
player_01_str.ent.pan = 90;

I'm not sure it's possible to add member functions to structs in lite-c, but if you can, you could also implement a method setPan() that sets the pan of the entity that is inside the struct.

Re: entitys and structures [Re: Excessus] #113218
02/22/07 10:46
02/22/07 10:46
Joined: Sep 2003
Posts: 407
inside to my
er_willy Offline OP
Senior Member
er_willy  Offline OP
Senior Member

Joined: Sep 2003
Posts: 407
inside to my
thaks, testing...

Re: entitys and structures [Re: er_willy] #113219
02/22/07 11:20
02/22/07 11:20
Joined: Sep 2003
Posts: 407
inside to my
er_willy Offline OP
Senior Member
er_willy  Offline OP
Senior Member

Joined: Sep 2003
Posts: 407
inside to my
ok many thanks, work!!!

sorry can you expand this ?
you could also implement a method setPan()



for the lovers of copy&paste
//-------------------
typedef struct
{
int height;
int weigh;
char name;
ENTITY* player_01_ent;
}PLAYERS;

//Reset variable from structures
PLAYERS* player_01_str = { height = 0; weigh = 0; name = "NULL"; }

//testing entitys on structures
function ball_life()
{
player_01_str.player_01_ent = my;

player_01_str.player_01_ent.flags |= TRANSLUCENT;//work!!!
}


//in main function

ent_create("earth.mdl",vector(0,0,100),ball_life);

Re: entitys and structures [Re: er_willy] #113220
02/22/07 11:25
02/22/07 11:25
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Code:

//-------------------
typedef struct
{
int height;
int weigh;
char name;
ENTITY* player_01_ent;
void setPan(var newPan) {player_01_ent->pan = newPan;}
} PLAYERS;

//Reset variable from structures
PLAYERS* player_01_str = { height = 0; weigh = 0; name = "NULL"; }

//testing entitys on structures
function ball_life()
{
player_01_str.player_01_ent = my;

player_01_str.setPan(90);
}



This works in C++ (not tested, but it should work), but I'm not sure this is allowed in lite-C or even C..

You might think the syntax of struct.entity.pan = value is easyer, but personally I prefer the struct.setMember(value) syntax because it allows you to check the input. Basically you can set rules INSIDE the object (not everywhere you use it) how it may be used. For example, if you only want pan values 0 to 180 to be allowed, you could add a check for that in the setPan() function.

Re: entitys and structures [Re: Excessus] #113221
02/22/07 11:29
02/22/07 11:29
Joined: Sep 2003
Posts: 407
inside to my
er_willy Offline OP
Senior Member
er_willy  Offline OP
Senior Member

Joined: Sep 2003
Posts: 407
inside to my
many many thaks, testing...

Re: entitys and structures [Re: er_willy] #113222
02/22/07 11:38
02/22/07 11:38
Joined: Sep 2003
Posts: 407
inside to my
er_willy Offline OP
Senior Member
er_willy  Offline OP
Senior Member

Joined: Sep 2003
Posts: 407
inside to my
function on structures... I thik what not work on c, only work in class(c++). not?

Lite-c get error.

I test this. but same error
void setPan(var newPan) {player_01_str.player_01_ent.pan = newPan;}

I agree with you, function on structures is a good idea.

Last edited by er_willy; 02/22/07 12:05.
Re: entitys and structures [Re: er_willy] #113223
02/22/07 12:11
02/22/07 12:11
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
In C++, you can also add methods (member functions) to structs (not just classes) but I think this is indeed a C++ addition to structs, and not a C feature..

One thing that you could probably do, but would make it a little uglyer:
Add a function pointer to your struct. Always initialize this pointer to point to a global function, that takes an instance of that struct, and the parameter to set.
Code:

// In the struct, named "somestruct":
void (*setPan) (somestruct, var);

// Global function:
void somestructSetPan(somestruct thisStruct, var newPan)
{
thisStruct.ent.pan = newPan;
}

// Before you can use the function pointer, you must initialize it:
somestructInstance.setPan = somestructSetPan;

// Now just call it:
somestructInstance->setPan(someStructInstance, 90);



Note that all this takes quite a bit of setting up, and you might forget to do something. So what you should do is create a function that sets all members to an initial value (and sets the function pointers correctly). Basicly the equivalent of a C++ constructor.

You could also leave out the function pointer, and just call the global function with the struct and the new pan value.

Again, all this is not needed because the struct.ent.pan also works, but in large projects with large and complex structs, doing object oriented programming is really beneficial.

Re: entitys and structures [Re: Excessus] #113224
02/22/07 17:28
02/22/07 17:28
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
You can have methods in structs, but only for interfacing external APIs. You can not define your own methods, although this could relatively easily be added in a future lite-C version.

Re: entitys and structures [Re: jcl] #113225
02/22/07 17:45
02/22/07 17:45
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
That would be pretty cool.
Would it also be easy to implement a this pointer like in C++ then?

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1