Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by AndrewAMD. 12/05/23 10:56
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (AndrewAMD, alibaba, fairtrader, ozgur, TipmyPip, Quad), 622 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Structs acting like Classes #124181
04/14/07 21:58
04/14/07 21:58
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
Can someone tell me, short and sweet, can structs act like classes? Is there some way you can mimic using functions and localized variables in the functions?

I recall hearing something like this somewhere. Since I am not 100% familiar with C or C++, and I know that C lacks features of C++, I need some help.

Re: Structs acting like Classes [Re: sheefo] #124182
04/15/07 03:43
04/15/07 03:43
Joined: Jul 2005
Posts: 34
Hong Kong
U
ultranet Offline
Newbie
ultranet  Offline
Newbie
U

Joined: Jul 2005
Posts: 34
Hong Kong
No, struct can't act as a class. Since a struct is just a collection of data and it does't has methods. It lacks many features of a class.
C-Script/Lite-C is a procedural language, not an object-oriented language.

Re: Structs acting like Classes [Re: ultranet] #124183
04/15/07 06:23
04/15/07 06:23
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
He's right, but if you adhere to some rules, it IS possible to do object oriented programming. You can mimic methods with function pointers and using the this pointer I think. You can use a constructor and destructor (although the USER of the 'class' must use it, he CAN break the rules and not use them, unlike in C++). And you could use private and public variables, but once again the user must follow these rules, the language won't stop you from using variables that are intended to be private.

Re: Structs acting like Classes [Re: Excessus] #124184
04/15/07 15:48
04/15/07 15:48
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I guess there is a work-around for functions. I could pass the struct as a pointer to the function so I can manipulate it like that, since there is no 'this' pointer in Lite-C.

Or, I can make a plugin and use DLL functions for every point of manipulation. But thats stupid because I can do similar things with functions and structs.

Thanks everyone.

Re: Structs acting like Classes [Re: ultranet] #124185
04/25/07 20:54
04/25/07 20:54
Joined: Oct 2006
Posts: 1,245
A
AlbertoT Offline
Serious User
AlbertoT  Offline
Serious User
A

Joined: Oct 2006
Posts: 1,245
Quote:

No, struct can't act as a class. Since a struct is just a collection of data and it does't has methods. It lacks many features of a class.
C-Script/Lite-C is a procedural language, not an object-oriented language.




Well up to a certain extent , C-Script is also ,in my opinion, a basic OOP
An entiy is an object having its own private variables
Thanks to the pointer "my" you can assign a generic function to a specific object consequently this function is more or less a method
You can not create abstracted classes which are not linked to an entity in the scene, that's true

Re: Structs acting like Classes [Re: AlbertoT] #124186
04/26/07 10:15
04/26/07 10:15
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
Correct me if I'm wrong, but the 'my' pointer is not useable in normal functions, only as a pointer to the entity using the fucntion.

I though Lite-C was OOP, but I knew that C-Script was not because before that I was using Ruby, which is a very good Object Oriented Scripting Language.

Re: Structs acting like Classes [Re: sheefo] #124187
04/26/07 11:49
04/26/07 11:49
Joined: Oct 2006
Posts: 1,245
A
AlbertoT Offline
Serious User
AlbertoT  Offline
Serious User
A

Joined: Oct 2006
Posts: 1,245
Well maybe I did not explain myself
Suppose you want to make a racing game
you have 10 cars in the race

Using C++ you define a generic class Car
This class contains generic variables : postion, speed etc
As well as generic set of functions, for example : Move()

Then you istance 10 cars
In the game play you call

car_00 .> Move()
.......

car_09 .> Move()

In 3DGS you create 10 entities car
Each car has its own set of variables
You create one only set of functions , for example Move() using the my pointer and one only special function Action for example UpdateCar

You assign UpdateCar to the 10 cars

The program loop thtrough the 10 entities updating their position, speed etc


I have been using Blitz3d for some years, a great software
However in Blitz you must declare 10 sets of variables and define 10 set of functions Move_00() ...Move_09() etc

From this point of view 3DGS is in my opinion a basic OOP

You can not create abstracted classes and you can not create a hyerarchy of classes

Lite_C should improve the OO capabilities

Last edited by AlbertoT; 04/26/07 11:55.
Re: Structs acting like Classes [Re: AlbertoT] #124188
04/26/07 13:33
04/26/07 13:33
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I see. I use that kind of stuff in my RTS a lot. I have lots of functions for different... functions, and I loop through an array of entities assigning them to the 'my' pointer.

I could not finish my RTS in C-Script due to the lack of OOP, so thats why when I converted my project to Lite-C I started to make very fast progress. I use structs everywhere I can


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