ID:1614573
 
(See the best response by Ter13.)
Code:
        Watered_Dirt
icon = 'Farming.dmi'
icon_state = "WateredDirt"
Pickable = 0
Click()
if(usr.OnProperty == 1 && src in oview(usr,1))
if(!istype(usr.InHand,/obj/Pickups/Seeds/))
usr.skalert("You must have seeds in hand.")
return
if(istype(usr.InHand,/obj/Pickups/Seeds/))
alert("DEBUG : Planted [usr.InHand]") //For debugging purposes only.
else if(usr.OnProperty == 0)
usr.skalert("This is not your property!")
return
else
return


Problem description:
Ok so if this was you how would you do it? My problem is in wanting to plant the seed and each seed having a proc in which is called when it is planted. What the proc will do is go through cycles of the plants growing stages,that is easy. What is not is getting my system to know that when the seed is planted to start the proc specific to that seed. I could do this with new() but that would cause problems because players can drop the seeds which uses new. Anyways I could do this with a lengthy proc using if statements I do not want to do that. I want to achieve this in a low number line of code. Any ideas or input is greatly appreciated.
-Thanks.
Typecast InHand as Seed if it's not already done so.
var/obj/Pickups/Seeds/S = usr.InHand

Then after you've planted it, assuming S is still in scope (it should be)
usr.InHand = null
spawn(0) S.Grow()
Make sure you check there's nothing already growing on the spot you are on (which you can get that /turf via usr.loc). You may want to pass that location on to your Plant() function as well :)
In response to Lugia319
That wouldn't work because every Seeds/proc would have to use a different name.
Best response
Well, the simplest way would be to spawn until the next growing cycle.

turf
dirt
var
moisture = 0
proc
ConsumeMoisture()
if(moisture)
moisture = 0
icon_state = "tilled"
return 1
else
return 0
Watered()
if(icon_state=="tilled")
moisture = 1
icon_state = "watered"
Tilled()
if(icon_state=="dirt")
icon_state = "tilled"

crop
var
list/stage_length = list(2000,2000,2000,2000)
proc
Grow(obj/plant/p)
if(p.stage<stage_length.len && p.loc)
var/turf/dirt/d = p.loc
spawn(stage_length[p.stage+1] / (d.ConsumeMoisture()+1))
p.Grow()

Harvest(obj/plant/p)
//check plant's stage number and give items

Planted(obj/plant/p)
Grow(p)

obj
plant
var
crop
stage = 0
proc
Grow()
stage++
icon_state = "[stage]"
var/crop/c = crops[crop]
c.Grow(src)

New(loc=null,crop_type=null)
..(loc)
src.crop = plant_type
icon_state = "0"
var/crop/c = crops[crop_type]
c.Planted(src)

var
list/crops = list("potato"=new/crop/potato) //just examples


This approach is fairly simplistic. I use singleton datums to do most of the work. The plants themselves don't contain the majority of the logic, it's the singleton crop objects that do the heavy lifting.
Wow thanks for your input, I am going to take some time to try to break this down and ingest it.
In response to Ter13
Never mind, that is actually a little overwhelming as well as demotivating.
In response to The WardenX
The WardenX wrote:
Never mind, that is actually a little overwhelming as well as demotivating.

What exactly are you having trouble with? His code is B(e)YOND easy to follow.
In response to Lige
Yes it is sir. Anyways here is a part of my system
                            if(istype(usr.InHand,/obj/Pickups/Seeds/))
var/obj/Pickups/Seeds/S = usr.InHand
new S.type(src.loc)
S.Grow()
Stage = 0



obj/Pickups
Seeds
icon = 'Seeds.dmi'
Tomatoe_Seeds
icon_state = "Tomato"
Amount = 1
screen_loc = "8,1"
proc/Grow()
usr<<"Tomatoe" //Grow stuff will go here only for testing


Ok how can I call a procedure based on what is planted? For example if I have a Tomatoe Seed in hand what would be the best way to call a proc in which it will grow? I can't really use a proc specific to the tomatoe seed type path due to the fact that it might not be the one in hand, getting planted.
Look at Ter's code again. The Grow() proc is under /obj/plant/. Based on your code, Grow() should be under /obj/Pickups/Seeds/, not /obj/Pickups/Seeds/Tomatoe_Seeds/.

All of the children under /obj/Pickups/Seeds/, including Tomatoe_Seeds will inherit the Grow() proc, which can be defined to fit all or it can be tailored to each case. Either way, you can still use your method of calling Grow() successfully if you move the proc as instructed.
That's exactly why I had set up that crop list.

Check this out:

obj/Pickups
Seeds
var
crop
proc
Plant(var/turf/t)
new/obj/plant(t,crop)


All you have to do is define a few seeds with a string set to a particular crop.

obj/Pickups/Seeds
Tomato_Seeds
crop = "tomato"

crop
tomato
//Define your growth states and harvest behavior here

var
crops = list("tomato"=new/crop/tomato)


All you have to do is define the type of crop something is, and all the behavior will translate downward in the hierarchy.

If you are still confused, ask more questions, because I can't help you understand without your help in trying to understand.

Also, I think part of the reason you are failing to grasp what I wrote is that you don't understand inheritance (polymorphism). Take a read through this page before continuing: http://www.byond.com/developer/articles/whitepaper
In response to Ter13
obj/Pickups
Seeds
var
crop
proc
Plant(var/turf/t)
new/obj/plant(t,crop)

Ok right there why are you using new/obj/plant if I am defining my growing behaviour in crop/tomato? In that case why should there even be a plant path?

I do understand inheritance if I didn't I would have never gotten as far as I have.
Ok right there why are you using new/obj/plant if I am defining my growing behaviour in crop/tomato? In that case why should there even be a plant path?

The growth behavior is in crop/tomato because crop/tomato is a singleton datum that stores all the information about a crop. The plant is just a physical representation in the world. The specific logical data for handling the growth cycle is all handled in the crop datum.

The reason I created that singleton (meaning there's only one in the world) to drive the behavior of the crop itself, was to reduce the amount of code in the world, and to make it so that every crop doesn't have a list of the growth stages. in its variables.
obj
plant
var
crop
stage = 0
proc
Grow()
stage++
icon_state = "[stage]"
var/crop/c = crops[crop]
c.Grow(src)

New(loc=null,crop_type=null)
..(loc)
src.crop = plant_type
icon_state = "0"
var/crop/c = crops[crop_type]
c.Planted(src)

Could you try and explain what's going on here?
obj/Pickups
Seeds
var
Crop
proc
Plant(var/turf/Farming/Tillable_Grass/T)
new/obj/Plant(T.loc)
icon = 'Seeds.dmi'
Tomatoe_Seeds
icon_state = "Tomato"
Amount = 1
screen_loc = "8,1"


Pumpkin_Seeds
icon_state = "Pumpkin"
Amount = 1
screen_loc = "8,1"

obj/Pickups
Produce
icon= 'Plants.dmi'
Tomatoes
icon_state = "Tomatoes"
Amount = 1

obj
Crop
Tomatoe
//Define your growth states and harvest behavior here

var
Crops = list("Tomatoe"=new/obj/Crop/Tomatoe)

obj
Plant


I've gotten there so far. The procs under the singleton datum still have me stopped.
Crops should not be an /obj. They should be datums. Review my type paths again.

Anyway, not sure what you mean by stopped. They should be pretty self-explanatory. What's got you stopped exactly?
In response to Ter13
You might as well make a demo out of this Ter, you're like 80% done for it. Add some comments, a quick mock example and boom! Done.
In response to Ter13
Stooped*