ID:1860536
 
(See the best response by Maximus_Alex2003.)
Code:
obj/Food
//proc that is usable by all obj's at the lowest level in this tree

Fruit
icon = 'Food.dmi'
icon_state = "Fruitbowl"


Apple
name="Golden Apple"
desc="This apple grants you the power to turn anything into gold!"
Click()
if(src in usr.contents)
for(var/mob/M in hearers(10))
hearers(10) << "[usr] reveals his [name]: [desc]"
Orange
name="Juicy Orange"
desc="The user of this orange is able to call upon an endless river of orange juice!"


Meat
icon = 'Food.dmi'
icon_state="Foodplatter"

Burger
name="Hamburger"
desc="The user who eats this will gain large love handles that can function as a flotation device!"

German_Meat
name="Brautwurst"
desc="The user who eats this will never be hungry again!"



Vegetable
icon = 'Food.dmi'
icon_state="Veggies"

Spinach
name="Can of Spinach"
desc="Toot toot! Whosoever eats this spinach, if he be worthy, shall possess the power of Popeye the Sailor Man!"

Brussel_Sprouts
name"Brussel Sprouts"
desc="BLECH! If anyone eats this they lose all their food-gained powers."


Problem description:Hi. I present to you my highly complex and advanced tree of objects relating to food. It's representative of what's currently in my source code but I changed/simplified it so it's more attractive to receive a response, and so that I could understand just in case someone decides to bust out a mosaic response filled DM/coding jargon that I'm not yet familiar with. Anyway there's the object Food, with its three "sub objects", Fruit, Meat, and Vegetable. Each of those use the same icon file but different icon_state as it's icon. Within them there's 2 specific fruits, meats, and vegetables, respectively with their own [name] and [desc].

What I could do is add a Click() proc for each specific food at the lowest level to display its [name] and [desc] but as far as I know that probably isn't the most efficient route to take. What I'd like to know how to do is add a single Click() (or any proc, really) under
obj/Food
that will do what the Click() proc does for the Apple in the code above. I want that proc to be accessible to the usr if they have any kind of food (apple, orange, burger, spinach, etc) in their inventory. I just don't know what kind of code I need to make it happen.

Any help?
Best response
So, let me get you correct on this...


You want a basic Click() command that will do this:
                if(src in usr.contents)
for(var/mob/M in hearers(10))
hearers(10) << "[usr] reveals his [name]: [desc]"

but then do extra food-specific things for each individual food like for example: Apple will show "[usr] reveals his [name]: [desc]" AND give +15 health to usr?

If that's the case, just have the basic
                if(src in usr.contents)
for(var/mob/M in hearers(10))
hearers(10) << "[usr] reveals his [name]: [desc]"

under Food and then in each individual food object have a modified use_food().

For example:
obj
food
verb
get()
set src in oview(1)
usr.contents += src
proc
use_food(mob/player)

Click()
if(src in usr.contents)
for(var/mob/m in hearers(10))
m << "[usr] reveals his [name]: [desc]"
src.use_food(usr)

fruit
apple
desc = "A delicious apple. Guarantees 5 HP or your money back!"
use_food(mob/player)
player.health += 5
player << "You gain 5 health!"
del src

orange
desc = "Orange you glad I didn't say banana?"
use_food(mob/player)
player.health -= 5
player << "You lose 5 health for that terrible joke!"
del src
meat
steak
desc = "This steak is still bleeding."
use_food(mob/player)
player << "That was delicious!"
del src
chicken
desc = "Why did the chicken cross the road?"
use_food(mob/player)
player << "Chickity China, the Chinese chicken!"
player << "You have a drumstick and your brain stops tickin'."
del src
Oh so if Click() is under 'obj/Food' it's automatically applied to the obj's under it? Ha! I was thinking I would have to use if(istype()) a little moment ago. And I see that the use_food() proc is what connects the Click() proc to the objs on the lowest level. Thanks man! This makes sense--I'm going to apply it to my code and see how it works.
Child /obj inherit their parent_type var/proc/verb/etc. unless you specify not to, or to add more than their parent_type have.
Hence why they're called Child/Parent.

obj/food/fruit/apple/ would be a child of obj/food/fruit/ which is a child of obj/food/ which is a child of /obj/.

If you make a proc in obj/food/fruit/apple/, it will only apply to obj/food/fruit/apple/. If you make a proc in obj/food/fruit/ it will apply to both obj/food/fruit/apple/ and obj/food/fruit/orange/ in my example.

And then you just differentiate the obj/food/fruit/apple/ proc and the obj/food/fruit/orange/ proc
In response to Maximus_Alex2003
Maximus_Alex2003 wrote:
Child /obj inherit their parent_type var/proc/verb/etc. unless you specify not to, or to add more than their parent_type have.
Hence why they're called Child/Parent.

obj/food/fruit/apple/ would be a child of obj/food/fruit/ which is a child of obj/food/ which is a child of /obj/.


If you make a proc in obj/food/fruit/apple/, it will only apply to obj/food/fruit/apple/. If you make a proc in obj/food/fruit/ it will apply to both obj/food/fruit/apple/ and obj/food/fruit/orange/ in my example.

And then you just differentiate the obj/food/fruit/apple/ proc and the obj/food/fruit/orange/ proc

Yeah I thought about this concept but I don't know why I was having a brain fart about it. I appreciate the help man.