VBGamer |
|
RE: a thing about classes Corre (0 replies, 0 views) (2000-Jul-22) There is a section in the VB help about classes. It explains how they work and how to use tem. Read it.
One thing that you can't do with UDT's but that you can do with classes is put code in them.
Let's say I'm doing a strategy game, which have several different units, that have different abilities and that act differently.
If I was to use UDT's, I would have to do a set of global functions to process ny units, like Unit_Move(MyUnit,...), Unit_Attack(MyUnit,...) etc. Each of these functions would have to check a variable inside the UDT, to see which type of unit it was, and by some If's or Select statements determine what action to take.
With classes, you would put the functions inside the class, and call them like MyUnit.Move(...), MyUnit.Attack(...). The code in each of these functions will only be used for that particular class.
Using classes in this case would make you code much more flexible, easier to read and maintain. To add a new type of unit, you'd simply create a new class, instead of modifying existing functions.
But if you really are interested in classes and what benefits you could get, read through the section in the VB help.
/Corre, MiCo Games
http://www.micogames.com |