ID:264367
 
Code:
obj/plant
icon = 'plants.dmi'
icon_state = "sprout"
var/seed

New()
sleep(10)
var/obj/O = new seed
O.loc = locate(src.loc)

mob/build/verb/plant_onion()
set name = "plant onions"
set category = "Plant"
var/obj/plant/P = new(src.loc)
P.seed = /obj/food/onion
P.name = "Onion Plant"
P.owner = src


Problem description:
What is supposed to happen is the player creates a generic plant object. When the player makes it, it changes the seed when the plant is made. After awhile the plant is supposed to bear food based on it's seed. But I keep getting a error for this. Can someone lend a hand?

At the time when obj/plant/New() is executed and it then calls new seed(), the seed var is still at its default value of null, and not a type. This is because it is only ever set after New() has already finished (and so execution returns to the verb). This can be circumvented in one way by initializing the object's vars in the beginning of New() by passing the wanted values in through new().
Note you're also using locate() with an invalid argument, and neither do you need to use it or even the whole line that call is on.
In response to Kaioken (#1)
Another way around New() delaying the verb would be to use spawn(10) in New() instead of sleep.
In response to Kaiochao (#2)
The weirdest thing, I tried to replace sleep() with spawn() and now it is giving me a error about undefined vars, even though it is defined just above it.
In response to Trosh Kubyo (#3)
    New()
spawn(10)
var/obj/O = new seed
O.loc = locate(src.loc)

spawn() creates an indented code block, like if(), else, for(), while(), etc.
In response to Trosh Kubyo (#3)
obj/plant
icon = 'plants.dmi'
icon_state = "sprout"
var/seed

New(loc,n,s,o)
seed = s
name = n
owner = o
sleep(10) //Dunno if you 'need' this delay or not, so I left it there
var/obj/O = new seed //you could even use 'new text2path(s)' if you wanted >_>
O.Move(locate(src.loc))

mob/build/verb/plant_onion()
set name = "plant onions"
set category = "Plant"
var/obj/plant/P = new(src.loc,"Onion Plant",/obj/food/onion,src)


Try that. It worked for me :)
Thanks everyone, I got it figured out.