**How to make a Patch Plant**Using the Chili Pepper Plant as an example

**The first thing you need to do is make an invisible flag agent**This agent is classified as 1 205 X, and stores information about your patch plant.**This means a lot of NAME variables.

new: simp 1 205 22935 "blnk" 0 0 9000

*The first thing you're going to do is define the number of your spawn script*This is the script that the patch core will trigger when it's time to spawn a fruit/bud/whatever.*I'm going to use script 1000 for this... we'll get more into it later.

setv name "spawn_script" 1000

*Now you have to define the file name and image number of the sprite that will represent your plant*when it is fully grown. This will be used both in placing a fruit/bud and serving as the little*indicator that shows on the hand when you're placing the patch.

sets name "sprite_file" "chilli"setv name "sprite_pose" 11

*finally, you need to define the classifiers for your produce

setv name "prod_fmly" 2setv name "prod_gnus" 8setv name "prod_spcs" 22935

*now personally, I like to define my blossoms as "fruit" all the way through the growing process,*and just keep them invisible to creatures until they are fully grown. You might chose to do it*differently and define them as flowers that later are killed and replaced with fruits. However*you choose to do it is up to you-- but the only agents that are going to be considered part*of your patch are those with those classifiers as defined above. Thus, once your flower is killed*and replaced with a fruit, the patch won't recognize it anymore-- so you'll have have to do some*more creative coding if you want to do it that way.

*Now that you have everything defined, you need to contact the patch core agent (1 1 22929) and let*it know that you're here-- the patch scripts will take it from there and generate the*placement windows, let the user choose options, and so on.

seta va00 targenum 1 1 22929 mesg wrt+ targ 1000 va00 0 0next

**That's it for your install script!

*Now for your spawn script-- this is 1000 as we defined it in the install script.

scrp 1 205 22935 1000 inst

*If this script is running, it's because the patch core decided it was time for your*patch to spawn a new bud. It has also sent the coordinates it has decided were proper in*_p1_ (x) and _p2_ (y). It has also stored the plane set by the patch options in the NAME*"patch_plane" variable.

*So first, create your little fruit to be:

new: simp 2 8 22935 "chilli" 14 1 name "patch_plane"

*again, I like to keep my blossoms invisible to creatures so they don't*try to eat them while they're still flowers. You also obviously don't want them to suffer*physics just yet.

attr 80 bhvr 48 accg 2 perm 64 fric 100 elas 30 aero 2

*And move it to the coords sent by the patch agent:

mvto _p1_ _p2_

*Now, a few new name variables have been defined in your patch flag agent since you last*left it-- these are settings that have been defined in the options window as well as a*unique patch ID number that has been generated. You'll need to copy these over to your*your budding fruit!

*The patch ID is important-- if you don't copy it over, the patch plant won't realize that *the fruit is there, and it will spawn another one, and continue spawning FOREVER.

setv name "patch_id" mame "patch_id"

*then there's the ticks as set in the options panel:

tick rand mame "tickfrom" mame "tickto"

*personally I like to define a default tick too, in case something goes wrong and the tick ends*up as 0.

doif tick eq 0 tick 200 endiendm

*And that is just about it.

*From here you pretty much script it like you would any other blossoming plant-- give it a timer*script to grow, ripen, become visible and so on. Of course, don't forget eat scripts,*collision scripts, etc.

*Keep in mind: when your plant is picked (or falls off the patch if you decide to code it like that)*aside from making it suffer physics, you'll also have to decide if you want to clear the*patch_id variable. If you clear it, it will no longer count toward the total number of *fruits growing on the patch, and a new one will spawn to take its place. If you don't clear*it, the script will keep counting it and until that fruit is eaten or otherwise disappears, *a new fruit won't spawn. If you haven't scripted your fruits to eventually decay, you may*wish to keep the patch_id variable intact so you don't have a patch that keeps spawning*endless numbers of fruits that pile up and slow down the game.

*Another thing you might consider doing is setting the tick to something static after the fruit*falls off the patch, so that the growth rate set by the user does not affect the decay rate of*the fruit. Personally, I choose not to do this, but it is an option to consider.

*This is my timer script:

scrp 2 8 22935 9

*if it's not fully grown, grow it to the next stage

doif pose lt 10 setv va00 pose addv va00 1 pose va00 stop endi

*if it is fully grown, add to its timer (ov00), and make sure creatures can see/grab it.

doif ov00 lt 10 addv ov00 1 doif attr = 80 attr 67

*also make it start smelling like a fruit

emit 6 0.01 endi stop endi

*if it's fully grown and has been sitting on the plant for 10 turns,*it should fall off the patch

doif attr = 67 attr 195 pose 11

*I'm going to chose to clear the patch_id variable so a new one can spawn where it fell.

setv name "patch_id" 0

*and if it's fully grown and already on the ground, it should add to its decay timer (ov01)

elif attr = 195 doif ov01 lt 10 addv ov01 1 else

*but if its been laying on the floor for 10 turns, go ahead and call it rotten.*I'm going to be lazy and just kill targ, but if you have proper sprites prepared,*turning it into detritus can benefit your ecosystem if you've got bugs and critters that eat it.

kill targ endi endiendm

*here's the collision script-- in this case if it's hitting the floor for the first time*it changes the sprite.

Not really; I think the only thing to be aware of is that you need to give the plants physics from the start, and you might want to make your first "stage" of growth an invisible or very tiny sprite if you don't want them to be plainly visible since they still spawn in the patch box and then fall to the ground.

Ground patches were one of those things that weren't really intended from the start, but ended up being a nice use for the existing framework anyway!

A solution for the flower/fruit problem would be keeping the flower hidden behind the fruit until the fruit drops. This way butterflies, hummingbirds and other flower-loving critters get to enjoy the tasty, tasty blossoms properly.

Amai, I might need more hand-holding with thinking about ground patch plants' first stage of being. I've been reading the scripts for the carrot and mushroom, and I'm just having some trouble thinking my way through them.

Hmm, what specifically is baffling you? I can try to make that segment a little more clear.

If you compare the chili spawn-code and the carrot-spawn code side-by-side, they're nearly identical with a few differences:- The carrot seed starts out with attr 208 to allow physics; it falls directly from its spawn-point in the box onto the ground, whereas the chili starts with attr 80 which doesn't allow physics-- obviously it wants to stay in place until it's grown!- The carrot has some additional code to determine which way it faces when it lies on the ground, but that's just...carrotyness.