ID:1908868
 
(See the best response by Kaiochao.)
Its been years since I have done any work with DM, I am trying to get back into it. So something I have been working on is set of skills.

What I want to do is build an abstract class that holds some default variables and functions and a constructor if possible. Each time a skill is called I would like it to call the constructor function is there anyway to do with DB?

//So like this

proc/abstract_skill_class/
var cooldown = 5
constructor()
check_cooldown_on_or_Off()

proc/abstract_skill_class/mage_skills_class
teleport()
//teleport stuff


So when I call mage_skill_class/teleport() its going to run the parent constructor() [check_cooldown_of_or_off()] and if I havent defined a cooldown for teleport it would be set to 5 automatically.




Best response
I don't think you'd ever directly call a constructor function, and classes aren't defined by starting with "proc/".
// define a datum, /skill
skill
var
cooldown = 5
next_use

proc
// returns TRUE when not cooling down
CanUse()
return world.time >= next_use

// calls Use() when CanUse() is true
TryUse()
if(CanUse())
StartCooldown()
Use()

StartCooldown()
next_use = world.time + cooldown

Use()


// a mage sub-class of /skill, /skill/mage
mage

// a teleport skill of the mage skills class
teleport
// cooldown defaults to 5
// CanUse(), TryUse(), and StartCooldown() are inherited

// Use() is inherited so "proc" isn't repeated
Use()
// teleport stuff
In response to Kaiochao
Is there anyway to have a proc automatically run when a proc is called?

So when I call Use(), CanUse() and TryUse() are automatically run?
In response to Mouchy
Is there anyway to have a proc automatically run when a proc is called?
No programming language is going to let you set it up so that procs "automatically run when a proc is called". You have to call things yourself, that's the point of programming.

So when I call Use(), CanUse() and TryUse() are automatically run?
You don't call Use(). You call TryUse().

The way I just wrote it, your interface (e.g. clicking a verb, or hitting a button) only has to call skill.TryUse() and the skill will either activate or fail due to cooldown, whereas you (the programmer) only have to override Use() to fill in what the skills actually do, assuming they get to activate.
A constructor would actually be like this:

skill
New() // this is the constructor
...
Del() // this is the destructor
...
..() // always call ..() in Del()