ID:1509686
 
(See the best response by Pirion.)
The age-old problem BYOND brings upon Anime-section players, I learned to code with BYOND in the Anime section's style (i.e washlists of vars that have no parent-type)

So, I'm going to be working on a little side project over the summer, and am trying to gather some reference points. (Either I'm really bad at looking, or the reference to this is burried REAL DEEP in the forums)

Here is an example of a var list I currently have
mob/Stats/var
Health = 0
MHealth = 0
Reiatsu = 0
MReiatsu = 0
Kills = 0
Deaths = 0


Now, because I realized I've only coded "Anime-Styled" with DreamMaker so far, I noticed I have no clue how to call upon those vars now.

An example of a proc
mob
proc
Death(mob/M)
if(!src)
return
if(!M)
return
if(!src.client && src.Health <= 0)/* This uses a different var list, which I named Enemy for the time being) */
M << "</b>You gained some combat experience from defeating [src]"
if(src.client && src.Health <= 0) /*this is where I need to start calling upon the Stat vars */
M.kills ++
src.deaths ++
src.Health = src.MHealth
src.Reiatsu = src.MReiatsu
world<< "</b><font color=red>[src] has been slain by [M]!"


How would I go about "Resolving" this issue. Do I make seperate "Death" procs for each type of mob? And how do I call upon the list of vars to begin with? Any other information you can directly give me or refer me to regarding optimal use of the polymorphic language would be absolutely great, and greatly appreciated!

why is Stats a child of mob?
In response to Kitsueki
Kitsueki wrote:
why is Stats a child of mob?

In an earlier thread of mine someone advised me to fully use the polymorphic language, and had made a var like so, I'll input a link to the thread.

http://www.byond.com/members/ Dm31st3r?command=view_post&post=1399298&first_unread=1
Uhm.. I just skimmed through that but I don't think that's the idea here.

You don't need to validate that src exists, because if it doesn't then this proc will terminate anyway.

if(!ismob(M))


Thats a safer check. You could pass 1 through as a parameter and if(!M) would evaluate M as true, thus continuing.

mob/var/blah works just fine, you don't need a specific mob type for it's stats.

Do you want your players to be /mob/Stats/ ? That's what they'll be.

Also pay attention to capitalization, it matters in variables. Deaths is not the same as deaths

I've never even heard the term 'polymorphic' and I learned to code fine. I suggest you let that term go and start thinking logically about it all. Start from the base and read about how the language works, because at the moment I get the idea you're confused about types, object children, and variables, all basic stuff.
Dm31st3r wrote:
Kitsueki wrote:
Uhm.. I just skimmed through that but I don't think that's the idea here.

You don't need to validate that src exists, because if it doesn't then this proc will terminate anyway.

if(!ismob(M))

Thats a safer check. You could pass 1 through as a parameter and if(!M) would evaluate M as true, thus continuing.

mob/var/blah works just fine, you don't need a specific mob type for it's stats.

Do you want your players to be /mob/Stats/ ? That's what they'll be.

Also pay attention to capitalization, it matters in variables. Deaths is not the same as deaths

I've never even heard the term 'polymorphic' and I learned to code fine. I suggest you let that term go and start thinking logically about it all. Start from the base and read about how the language works, because at the moment I get the idea you're confused about types, object children, and variables, all basic stuff.

Solid points made. I'm adequate in coding with a regular var list with no child/parent types. I was simply recommended to utilize a bigger portion of the DM language so I'm trying to look into it as much as I can.

> if(!ismob(M))
>

Would this even work? Both options in the Death proc involve mobs, the first being AI and the latter being players.



Edit: Nvm, see what you did there. I was fiddling around with the code too much and added something unneccesary
In response to Kitsueki
Best response
The term 'polymorphic' refers to overwriting needed behavior for each needed class. Have you ever overwritten Move for just mobs? In that case, you've benefited from polymorphism. No harm is knowing what it is you're using.
In response to Pirion
Fair enough. I think he's reading a little too deep into it though. If thats the case, polymorphic programming is more or less inheritance.
I guess I didn't post an example of what you're looking to do here.

mob
combatant
var //all combatants have some stats
Deaths = 0
Kills = 0
Health = 100
MaxHealth = 100
Strength = 10
Magic = 5
ExperienceOnDeath = 0
TotalExperience = 0
NextLevel = 1000
Level = 1

proc
TakeDamage(mob/combatant/c, amount) //Filter all damage through here
if(!istype(c)) return //if this isn't a combantant, it cannot deal damage.

src.health -= amount
CheckDeath(c) //check if dead

CheckDeath(mob/combatant/c)
. = IsDead() //this makes it return if the user dies.
if(.)
GiveExperience(c)

IsDead()
return Health <= 0

GiveExperience(mob/combatant/c)
c << "You gained some experience from defeating [src.name]."
c.RecieveExperience(ExperienceOnDeath)

RecieveExperience(amount)
TotalExperience += amount
while(LevelCheck())
src << "You advanced to level [++Level]!"
NextLevel += Level * 1000 //liner, but it's an example :)

LevelCheck()
return TotalExperience >= NextLevel

mob
combatant/player // for players
CheckDeath(mob/combantant/c) //now we're overwriting this.
/*Including the following line would give experience when players/mobs kill the player
. = ..()

*/

. = IsDead() //if we don't call the parent, we need to find out if they died.
if(.)
world << "[src.name] has been slain by [c.name]!"
c.Kills++ //give c the kill count
Deaths ++ //give src the death count
Revive() //revive src
proc
Revive() //this is specific to combantant/player, however we could put it on the parent type, and put the npcs on a respawn counter.
src.Health = src.MaxHealth
//respawn location set here


Now, you can create enemies by adding them to the parent of combatant.

mob/combatant/Troll
Health = 1000
MaxHealth = 1500
Strength = 20
Magic = 0
ExperienceOnDeath = 1000


This would make a sub-type of combatant, that gives experience on death, and that kills players.
I think the point of polymorphism is for things like this:
animal
proc/speak()

cat
speak() world << "meow"

dog
speak() world << "woof"

bird
speak() world << "tweet"

mob/Login()
// we have a variable defined as an /animal
var animal/pet

// the /animal variable can be set to any child of /animal
// and the speak() method can be accessed no matter what kind
// of animal the variable is referring to.
pet = new /animal/bird
pet.speak()

pet = new /animal/dog
pet.speak()

pet = new /animal/cat
pet.speak()

// we don't care what kind of animal we're using if we
// want it to "speak" because every animal has the method
// for speech defined (even if it does effectively nothing)
Thanks for the great examples, I see how parent/child types are utilized like that. If I want both an enemy and a player to use the same death proc, i'd have to have their vars under the same child/parent list, or make seperate procs for them. (this is assume I do nothing with parent/child listings in the attacks that kill them)
In response to Pirion
Why do you pass a /mob/combatant type through as a parameter here? These procs look like they should always only ever be called for their src object anyway.
It is the attacker. In order to provide experience (RecieveExperience is called by GiveExperience for c) and say who killed them.