ID:1864224
 
(See the best response by Mightymo.)
Problem description: Not so much a problem as to more of a question. You'll see in the code below. If you need me to expand on anything let me know. I'm not the greatest at explaining things.

Code:
obj
var
limit
amount //do these variables get assigned to every object now in the game whether or not they are ever used?

proc
remove_amount(n as num)
src.amount-=n
//remove code

weapons //for example I don't want weapons to have amount
parent_type = /obj/

sword
equipped

potions //but I do want amounts with potions?
parent_type = /obj/

health_potion
limit = 5
amount

food //or even food?
parent_type = /obj/

chicken
limit = 5
amount
Best response
Yes, but this suggests that your hierarchy should be different.

obj
Stackable
var
limit
amount
proc
remove_amount(n as num)
src.amount-=n
//remove code

weapons
parent_type = /obj/

sword
equipped

potions
parent_type = /obj/Stackable

health_potion
limit = 5

food
parent_type = /obj/Stackable

chicken
limit = 5


Or however it may be categorized.
Ahhh I see, I never knew it could be done that way, Thanks.

Also for another example, is there a specific way to do this?

obj
proc
give_description()
world<<"[src.description]" //how do i stop this being an undefined variable or is this impossible?

weapon
parent_type = /obj/

sword
var
description = "This is a sword"

verb
description()
give_description()


Also as a note i realize this is a terrible example. I also know BYOND has desc inbuilt.
I'm not confident that I know what you are asking. Are you attempting to use a more generic type for the process to display the more specific type's variable? That wouldn't even compile, and in this case only works because description is built in.

If you're just trying to keep description a filled string, just make sure to define it for all objects that would call give_description().
No sorry I'll try to explain it a little better.

Say for example I have a variable under the weapon datum and a proc outside of that datum. Then i use the variable in that proc it's an undefined variable right? How do i stop that from being an undefined variable?

proc
random_proc()
world<< src.random_var //random_var is under the random datum but it's undefined.

random
var
random_var

verb
do_stuff()
random_proc()


You need to define a proc as part of the datum in order to access that object's variables.

random
var
random_var

verb
do_stuff()
random_proc()
proc
random_proc()
world<< src.random_var


If the proc is truly supposed to be global, then you need to pass the datum instead.

proc
random_proc(var/random/r)
world<< r.random_var

random
var
random_var

verb
do_stuff()
random_proc(src)
In response to Mightymo
Mightymo wrote:
> proc
> random_proc(var/random/r)
> world<< r.random_var
>
> random
> var
> random_var
>
> verb
> do_stuff()
> random_proc(src)
>


This is what I was always looking for thanks, I tried something very similar to this before but instead of var/random/r i just var/r. Thanks for the help.

No problem.