Teen Programmers Unite  
 

 

Return to forum top

MORE User-Defined Types - Multiple levels???

Posted by Brok3n_Link [send private reply] at July 15, 2002, 08:02:49 AM

PS: this is vb6

right ok, it didn't work ok, and it still doesn't, i tried sometihng else but it didn't work.

ok, i'm making a game based on the Inquisitor Gameplay by Games Workshop. I need to have an array of player 'objects' that i can refer to with multiple levels:
eg. Player(1).BodyParts.LeftLeg.Damage = 0

This is what i'm using so far, but isn't working.
If anyone has a better idea than using UDT then please tell me, otherwise could you tell me what is wrong with the following code? on third thought, is it even possible???
Help much appreciated people. thanks

Type BodyPartVars
Name As String
Cond As Integer
Armour As Integer
BodyPartDamage As Integer
End Type

Type HandVars
Name As String
Equipped As String 'as CloseCombatWeapons?
End Type


Type tBodyParts
Head As BodyPartVars
Chest As BodyPartVars
Abbs As BodyPartVars
Groin As BodyPartVars
LLeg As BodyPartVars
RLeg As BodyPartVars
LHand As HandVars
RHand As HandVars
End Type

Type ClassTypeVars
None As String
Avatar As String
Inquisitor As String
Scout As String
GunFighter As String
Cultist As String
Fanatic As String
WitchHunter As String
FarSeer As String
Librarian As String
Warrior As String
Civilian As String
GaurdVeteran As String
ImperialEngineer As String
Commander As String
TitanLegionOfficer As String
End Type

Public Type PlayerCharacter
Owner As String
Name As String
Class As ClassTypeVars
Gender As String
Race As String 'Character's race
locX As Integer ' \
locY As Integer ' -> Location on the current area (X,Y)
Damage As Integer
DamageTotal As Integer 'Max Damage

BodyParts As tBodyParts

Equipment As String
RangedWeapons As String
CloseCombatWeapons As String

Items As String 'Items the char has (Inventory)
Wear As String 'All the items one char wears
End Type

None = "No Class"
Avatar = "Avatar"
Inquisitor = "Inquisitor"
Scout = "Scout"
GunFighter = "Gun Fighter"
Cultist = "Cultist"
Fanatic = "Fanatic"
WitchHunter = "WitchHunter"
FarSeer = "Far Seer"
Librarian = "Librarian"
Warrior = "Warrior"
Civilian = "Civilian"
GuardVeteran = "Imperial Gaurd Veteran"
ImperialEngineer = "Imperial Engineer"
Commander = "Commander"
TitanLegionOfficer = "Titan Legion Officer"

Public Player() As PlayerCharacter

Posted by IIPen [send private reply] at July 15, 2002, 05:06:21 PM

I dunno what`s wrong with your code... it appears to be correct... I cannot think of anything else from what you gave here... guess that`s one of the examples where C++ takes advantage over VB...

P.S. I think it would be better to use linked list rather than defined types...

Posted by CodeRed [send private reply] at July 15, 2002, 05:44:48 PM

Wow, spend some time thinking about what you want to do before writing a shitload of garbage code like that. If you want to do something this complicated consider using another language

Posted by Zandalf [send private reply] at July 15, 2002, 06:22:22 PM

Funny, I thought TPU was supposed to be a supportive learning environment, not just another newsgroup where whenever an aspiring programmer asks a question, his entire lifestyle is berated because people can't accept that he's _just starting_.

IOW, lay off, Red

Posted by taubz [send private reply] at July 15, 2002, 08:05:20 PM

Ignore CodeRed. He's like that.

Brok3n_Link, it would be very very helpful if you gave us the error message that you're getting (and the line that it's on) or explain *what* doesn't work.

- taubz

Posted by CodeRed [send private reply] at July 15, 2002, 11:16:25 PM

My comments about thinking and planning before coding and considering another language are both valid points, thank you. And wouldn't you call this garbage code?
"
None = "No Class"
Avatar = "Avatar"
Inquisitor = "Inquisitor"
Scout = "Scout"
GunFighter = "Gun Fighter"
Cultist = "Cultist"
Fanatic = "Fanatic"
WitchHunter = "WitchHunter"
FarSeer = "Far Seer"
Librarian = "Librarian"
Warrior = "Warrior"
Civilian = "Civilian"
GuardVeteran = "Imperial Gaurd Veteran"
ImperialEngineer = "Imperial Engineer"
Commander = "Commander"
TitanLegionOfficer = "Titan Legion Officer"
"

There are much easier ways to do that

Posted by gian [send private reply] at July 16, 2002, 01:18:18 AM

TPU *is* a supportive learning environment, but Codered isn't really part of TPU!

Posted by Zandalf [send private reply] at July 16, 2002, 01:32:28 AM

gian - Aaahhh...

Red - yes, there are easier ways to do that. _however_, instead of saying that it sucks, offer a suggestion on how you would do it better, like llPen's P.S.

on a completely O/T note: I must admit, I tried reading the MT forums just a bit ago, and I must have gotten caught up in some age old rift in the populous, but I feel sick to my stomach. So thank you gian and everyone else for making TPU what it is (yes, you too Red, just need to smile a bit ^_^) ... not that I would know or anything, me and my massive 6 or so posts ^_^;;

Posted by CodeRed [send private reply] at July 16, 2002, 05:59:39 AM

According to the usage stats, I am the 3rd largest part of TPU Gian...

Posted by IIPen [send private reply] at July 16, 2002, 05:59:48 AM

Let`s go back to Brok3n_link`s problem ok??? Brok3n_link do as taubz says: post us smth more...

Posted by gian [send private reply] at July 16, 2002, 05:03:11 PM

Codered: That doesn't mean the rest of us accept you!

Posted by Brok3n_Link [send private reply] at July 16, 2002, 10:16:51 PM

ok, sorry guys, had to post in a hurry, and my computer has been in pieces. so

My question was, I need an array of multiple level user-defined type. eg.
Player(ID).Bodyparts.LeftHand.Holding = Nothing
but i have since worked out how to do this, BUT, my other questiois, would it be easier, more efficient/bettter code preactce to use a class? no idea how to do this, but i'll find out if you say it's better. Thanks for your POSITIVE posts.

thanks for yas help.

BTW: The 'garbage code' you re referring to wasn't auctually code, it was some notes i included to show that the ClassVars type had values. sorry i didn't speify this, but as i said, i was in a rush.

Brok3n Link
brok3n@iinet.net.au

Posted by Zandalf [send private reply] at July 16, 2002, 10:28:35 PM

Glad that you're figuring out how to do what you're trying to ^_^.

as for C++ classes (which is what I assume you meant) vs. VB types, you ask a lot of small questions. Easier: you'd have to learn a new programming language, so probably not. More efficient: yes, easily, and there is more you can do with it too. Better code practice: you're comparing two different programming languages, so it's hard to say. If you want the good parts of VB to go along with your code, I'd say switching wouldn't be good coding practice. However, if you can work around some of the difficulties that C++ provides in terms of UI creation, then it's better practice to move to C++.

So really, you're looking at either learning a new language, or just finishing it like this, and then maybe later recreating it when (and if) you learn C++.

But it's definently good to see that you've embraced OOP, I know a few poeople who would be afriad to use more than one . operator for an expression.

Also, codered, gian - Look, please don't fight over something this silly. This doesn't need to turn into some huge prick waving contest. Honestly, I just wanted to see if I could get codered to see the other side of the coin.

Posted by gian [send private reply] at July 17, 2002, 12:09:49 AM

Zandalf, we have been at each other's throats for almost 2 years... it's not going to stop right away :-)

Posted by buzgub [send private reply] at July 17, 2002, 02:26:41 AM

hmph. VB does have classes. If you think being able to attach methods to your types would be useful and would make your code clearer, using classes may be worthwhile. On the other hand, I don't see how the traditional advantages of OOP (encapsulation, modularisation, and features like inheritance, polymorphism and so on) would be useful in this case, so I would continue as you are now. It's your choice, though.

Posted by Psion [send private reply] at July 17, 2002, 08:05:33 AM

As to CodeRed and gian, I've taken to deleting their pointless argument posts in the past. I'll probably do it again if they reply to this or argue elsewhere.

Posted by Zandalf [send private reply] at July 19, 2002, 01:04:21 AM

You'll have to forgive the newbie, I'm still working on my Government and Politics of the TPU forums class ^_^

and VB has classes? that's news to me. why would they bother to implement types if they have classes then?

Posted by buzgub [send private reply] at July 19, 2002, 01:38:09 AM

I believe types were added as a feature of basic, and so probably would have been there close to the first release of VB. Classes would have been added later as a special VB-specific extension to the basic language.

Posted by Zandalf [send private reply] at July 19, 2002, 01:47:15 AM

well, I can understand the process that led to such a decision, but why do it if there is already something that can serve all the necessary purpuses? or does type in basic relate more directly to struct from c++?

Posted by buzgub [send private reply] at July 19, 2002, 01:50:04 AM

Similar to structs in C rather than to structs in C++, I think. Neither C structs or Basic types can have functions in them (but C structs can hold function pointers), and neither can do stuff like inheritance.

Posted by Zandalf [send private reply] at July 19, 2002, 01:59:52 AM

aaaah... it's all coming back to me... I remember when my VB-obsessed friend was very happy that 6 was going to have classes. not that it meant anything to me at that point, but it does now.

and yes, i meant structs from c, not c++, I don't think you should put functions in C++ structs even today.

Posted by unknown_lamer [send private reply] at July 19, 2002, 09:02:53 AM

What is wrong with functions in C++ structs? I like to put at least a constructor in the struct to make it easier to initialize (I know, I know..constructors don't exactly count as functions).

Posted by Zandalf [send private reply] at July 19, 2002, 01:09:39 PM

Nothing's wrong with it, I just learned C first, and so I learned that you can't put functions in structs. Since classes can, I use structs for ADTs that don't need functions (although I am beginning to see the merits of constructors in certain examples)

Posted by CViper [send private reply] at July 19, 2002, 01:48:58 PM

basicly structs and classes are the same thing in c++ only that structs have public visibility by default, classes have private/protected (don't remember exaclty)

But i also use structs as datatypes and for everyting else i use classes. Dosent matter much i'd guess :)

Btw: can one add private/protected members to structs? Never thought about that...

Posted by Brok3n_Link [send private reply] at July 20, 2002, 07:54:22 AM

ok thanks guys for all your help and, in gian and codered's arguing, entertainment!

nice debate going tho...

i think i'll stick to types here, and probably make this one of my last projects before i begin my endeavor to learn c++ PROPERLY(i've had my hax with it....)
righty, cyas thanx again

Brok3n Link
brok3n@iinet.net.au

Posted by unknown_lamer [send private reply] at July 21, 2002, 10:55:45 PM

CViper: yep (a struct is just a class with everything public by default).

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.