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.
With Predefs |
<FONT color=#ffffff size=4>Without Predefs |
obj/shirt |
obj/shirt |
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 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
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.