ID:36592
 
Keywords: beginner, tutorial

Predefs? What is a predef? It is my short hand for "Pre-definition". Now, what is a pre-definition? Pre-definitions are a way to make the most out of your code, while taking up the least amount of space. The technical term for this is "inheritance". Make sure you remember that, because you will normally hear it called inheritance rather than predef.

But Scoobert, you're still not making any sense!

You're right. Let's go over some examples.

<TABLE id=AutoNumber1 style="BORDER-COLLAPSE: collapse" borderColor=#111111 cellSpacing=0 borderColorDark=#000000 cellPadding=0 width="100%" bgColor=#555555 borderColorLight=#000000 border=1>

With Predefs

<FONT color=#ffffff size=4>Without Predefs
 

obj/shirt
     icon='clothes.dmi'
     icon_state="shirt"
     var
          wear
obj/shirt/blue
     icon_state="blueshirt"
obj/shirt/red
     icon_state="redshirt"
obj/shirt/yellow
     icon_state="yellowshirt"

 

obj/shirt
     icon='clothes.dmi'
     icon_state="shirt"
     var
          wear
obj/blue_shirt
     icon='clothes.dmi'
     icon_state="blueshirt"
     var
          wear
obj/red_shirt
     icon='clothes.dmi'
     icon_state="redshirt"
     var
          wear
obj/yellow_shirt
     icon='clothes.dmi'
     icon_state="yellowshirt"
     var
          wear

In that snippet, I didn't do half of the work that most people do. Rather than changing the icon for every one of the objects, I just made it a basic property of all objs that fall in the "shirt" parent type. (As I did with the "wear" variable.)

That's great! But I want it to do more.

That's good, because it can. Say you want all the shirts to have a "wear" verb and a "remove" verb. Yup, predefs can do it. Let's try this:

<TABLE id=AutoNumber2 style="BORDER-COLLAPSE: collapse" borderColor=#111111 cellSpacing=0 cellPadding=0 border=0><TD borderColor=#555555 bgColor=#555555>obj/shirt
     verb
          wear()
               //(Insert whatever your wear proc does)
          remove()
               //(Insert whatever you remove proc does)
 

That's helpful, but what if I want to change the verbs for special objects?

This is called "overriding". Ask, and you will receive:

obj/shirt/magic
     icon_state="magicshirt"
     wear()//Notice that I didn't add the word "verb" this time
          //(Insert what the magic shirt should do that's so special)
     remove()
          //(Insert whatever it does when you remove it)
 

Wait; you messed up! You didn't add the verb type path before the verb names.

Simple -- it was previously defined, so Dream Maker recognizes and knows that the new definition is actually overriding the former. This also works with vars and procs. You don't have to add "var" on the line. Example:

<TABLE id=AutoNumber4 style="BORDER-COLLAPSE: collapse" borderColor=#111111 cellSpacing=0 cellPadding=0 bgColor=#555555 border=0>
obj/shirt
     var
          color

obj/shirt/blue
     icon_state="blueshirt"
     color="Blue"

Oh. Now I get it. That makes sense.

I know, I'm smart. But wait, there's more! What if you wanted to call the first defined verb, but wanted to add something to it, too? It's not that hard. Just look:

<TABLE id=AutoNumber5 style="BORDER-COLLAPSE: collapse" borderColor=#111111 cellSpacing=0 cellPadding=0 border=0><TD bgColor=#555555>obj/shirt/magic
     icon_state="magicshirt"
     wear()
          ..() //Add this to call the parent proc
What is this creepy ..() thing?

That calls the proc or verb's parent. When it comes to coding, the parent is the branch above in a tree of coding. It's not necessarily at the top of the page, but it's where your object is based. Can you point out the parent verb in this example?

<TABLE id=AutoNumber6 style="BORDER-COLLAPSE: collapse" borderColor=#111111 cellSpacing=0 cellPadding=0 bgColor=#555555 border=0><TD width="100%">obj/appletree
     icon='trees.dmi'
     icon_state="apple trees"
     verb/pick()
          usr.contents+=new/obj/apple
          usr<<"Yay, a yummy apple"

obj/appletree/green
     icon_state="green apple trees"
          pick()
               ..()
               usr<<"And it is green too"

Oh, oh! I found it!

You did? Then show it to me:

      verb/pick()

Very good. I think you have learned all that I can teach you on this subject. Have fun! Now you are better equipped to handle a large game with ease, with the most efficient code.

 

This tutorial was created by Scoobert and was fixed up by Volte and Guy T.

Heh, I was actually going to email you about me cleaning that up a bit, but I'll let it go. It actually isn't too bad, but I was going to change the title to "Inheritance", and drop the whole predefs things all together. Oh well, I snoozed and I losed.
I learned something today, yea +1.
I'm really not a fan of the "predef" terminology, myself. No need to invent a completely new word for the idea when there's a perfectly good one already. =)
Oh, I agree, now. When I wrote this, I didn't actually know they had a name, so I just made something up. That's why I was going to write Gug an email about revamping it, but too late for that.
what? danial.beta is scoobert? someone should write an article about who is who.
I just need a name tag saying "The BYONDer formerly known as Scoobert"
I could have sworn I posted a comment on this already... am I going crazy?