Alright, I'm working on a plant system, and it works swell so far, except for one thing. First off, I'll describe what it does and should do.
You place the seed on the ground and plant it. What it does is bury itself, create the plant object(which should grow) and delete itself. The problem I'm having is how do I get it to start growing automatically?
Any help is appreciated.
ID:164957
Mar 20 2007, 3:06 pm
|
|
Mar 20 2007, 3:37 pm
|
|
Perhaps a show of code would help.
|
In response to Tweelik
|
|
I don't really think I need to show the code, All I'm looking to do is have it start a function automatically when it creates the new object.
|
In response to Bwgmon
|
|
Have you tried making a procedure containing the function needed, then calling it on the object?
|
Well, it's been months since I touched DM, but here is what I would do.
Let's say you have your plant object and procedure to grow: obj If you want something to happen when it is created, assuming you do something like new /obj/plant(loc), you can use the New() function. obj And viola! Your plant now grows! |
In response to Tweelik
|
|
Actually, no. I honestly don't know how to do that.
|
In response to Bwgmon
|
|
Look at XxDohxX's example, its what your asking for and it'll work.
|
In response to XxDohxX
|
|
Alright, I'll post down the relevant parts of the code...
<code>obj/plant/seed/ carrot icon='PlantCarrot.dmi' icon_state = "seed" name = "Carrot Seed" value = 5 plantable = 1 verb/Plant() set src in oview(1) if(plantable == 1) plantable = 0 flick("planting",src) sleep(18) icon_state = "0" new/obj/plant/carrot(loc = src.loc) del(src) else return()</code> Seed, and here's the plant: <code>obj/plant carrot icon='PlantCarrot.dmi' icon_state = "0" name = "Carrot Sprout" fertilizeable = 1 fertilized = 0 water = 5 alive = 1 growing = 1 color = "orange" proc Grow() if(alive == 1) growing = 0 water -= 1 world<< "Water Level = [src.water]" sleep(150) if(icon_state == "0") icon_state = "1"</code> This is a slightly buggy version, since I tried making it use a proc. It went by verb beforehand. |
In response to Bwgmon
|
|
It's looking fine to me...now just add on a New() to obj/plant/carrot that will call Grow(), as I did in my example above.
Or, you can do this: (taken from seed part of code) if(plantable) If you have any questions on how this works, or if you are just plainly confused, let me know. |
In response to XxDohxX
|
|
Why aren't you using if(plantable) there?
|
In response to Popisfizzy
|
|
I edited it. I didn't really read through his code after I copied it... I just wanted to give him the context of where I was adding in, just so he didn't get lost.
|
In response to XxDohxX
|
|
Excellent! It works!
Is there any way to make it delete the seed as soon as it calls the Grow()? It leaves the seed object there until the plant dies or the plant finishes growing. |
In response to Bwgmon
|
|
Of course. Note that when an object is deleted, all procs that have it set to src (and procs called by them) are stopped. You can prevent that by detaching the proc/verb from src:
var/obj/seed/S = src //keep a reference to src |