Basic plant script
The Install Script
- Create the plant!
new: simp 2 4 50000 "sharmflower" 6 0 rand 200 6000
But what does this mean?
- new: simp - creates a new simple agent
- 2 is the family
- 4 is the genus; 4 = plant
- 50000 is the species
- "sharmflower" is the name of the image file which is situated in the images folder. So, this agent uses the image 'sharmflower.c16'. (Although, if no c16 is found, an s16 of the same name will be loaded). See File:Sharmflower.c16 to download this file.
- 6 is the number of images the plant can use (we want to use images 0-5 in the sharmflower sprite).
- 0 is the image number to start counting these from (So, 2 3 would give the plant 2 images, 3 and 4).
- rand 200 6000 sets the plane of the agent randomly from 200 to 6000.
The next few parts set the object's properties.
- perm is the permeability of the object. It goes from 0 to 100, 0 meaning that it can go through anything, and 100 meaning it can't go through anything. In this case, it can go through some types of floor and wall, but mostly can't.
- emit is the smell an object emits. Creatures navigate using smells, so its important that objects emit them. In this case, it's emitting carbohydrate smell.
- fric is the friction of an object as a percentage of velocity while moving along the ground lost per tick.
The next part is setting the variable we will use.
setv ov10 rand 200 1000
In this object, ov10 is the lifespan of the plant. We're setting it randomly from 200 to 1000. We'll see how to use this variable later.
Almost done with the install script! There is one more little chunk of code here.
mvsf game "CreatorX" game "CreatorY"
velo rand 10 25 rand 0 -10
This will move the object to the Creator, whether it be the DS Agent Injector or the C3 Creator.
- mvsf moves the current targ to a location on the map near the coordinates specified.
- velo sets the velocity of the current targ. Agents move this distance in pixels (less the affect of air resistance, gravity, etc.) per tick.
- This is how often the timer script is called - this timer script is called every 3 seconds.
You've just finished the install script! Now, moving onto the next script...
The Timer Script
scrp 2 4 50000 9
- This line tells the engine that the following lines are a script.
- scrp = script
- We have to write the classifier of the agent the script refers to.
- 9 is the number of the script : here, 9 means 'timer script'
- This makes it so that the timer script will run once, and then, never again. This can be useful as a resource-saving measure.
gsub grow gsub live gsub seed gsub die
- gsub means : "jump to the subroutine" - so here the script will jump to the subroutine 'grow', then 'live', then 'seed', then 'die'.
- A subroutine is defined by two tags.
- 'subr' "name of the subroutine" will begin the subroutine.
- 'retn' will end it.
- Now we're going to make the plant grow.
subr grow setv va00 pose reps 5 wait rand 40 80 addv va00 1 pose va00 repe retn
- As said before, 'subr grow' opens the subroutine - here the name is 'grow', but you can use any name you want.
- The image file has 5 images that we're allowing the plant to use, and the base image is 0.
- 'pose' defines the image used by the plant at the moment.
- 'setv va00 pose' means we're setting the pose number in a variable, and this is because we can't add any values directly to the pose.
- 'reps 5' means that the lines which are following will be repeated five times (so that the sharmflower grows to maturity, but not beyond).
- If you want something to be repeated, take it inside 'reps X' and 'repe', where 'X' is an integer
- 'wait rand 40 80' means the script will wait randomly from 40 to 80 ticks.
- We've just added 1 to va00 - we've done this because we want to change the pose from 0 to 1.
- Now we can set the pose to va00 : 'pose va00' means : set the pose to the number contained in va00.
- 'repe' : this is the closing tag of the 'reps' command.
- The pose changing is repeated five times, because we want to move from pose 0 to pose 5
- 'retn' closes the subroutine.
subr live loop doif ov10 ne 100 setv va01 ov10 subv va01 1 setv ov10 va01 endi wait 1 untl ov10 = 100 retn
- 'subr live' opens the subroutine 'live'.
- 'loop' is the first part of the command which will make a part of script loop.
- 'doif someting' means 'do only if the something is true' - a doif must be closed by 'endi'.
- Here we say: do only if ov10 isn't equal to 100.
- 'setv va01 ov10' means we set the value of ov10 in va01 - 'setv' can be used like this too.
- 'subv va01 1' will subtract 1 from va01.
- 'endi' closes the 'doif' tag.
- 'untl something' is the closing tag of the 'loop' command - the script will loop until the condition 'something' won't be true.
- Here the script will loop until ov10 is equal to 100.
- 'retn' closes the subroutine.
- Now we've waited some time, and the plant has 'lived' enough to make seeds.
subr seed setv va10 posx setv va11 posy reps rand 2 5 new: simp 2 3 50000 "blank" 1 0 1000 attr 195 bhvr 0 elas 0.5 aero 2 accg 0.2 mvsf va10 va11 velo rand -10 10 rand -10 0 tick 5 targ ownr repe wait rand 40 90 retn
- 'posx' and 'posy' return the X and Y coordinates of the current targ.
- Randomly repeat the creation of seeds 2-5 times, so, 2-5 seeds will be created.
- blank.c16 is a small, blank sprite that is useful for things you do not wish the player to see or interact with.
- Because we just created a new seed, the timer script is now targeting the new seed. We explicitly return the targ to the plant by using targ ownr.
- The plant has grown, lived and seeded. It can now die.
subr die loop setv va00 pose subv va00 1 pose va00 wait rand 40 80 untl pose = 0 setv va20 256 loop subv va20 50 alph va20 1 wait 7 untl va20 <= 6 kill ownr retn
- Note that this death script does not progress to the wilting frames. The plant now grows backwards, from its adult pose to its seedling.
- 'wait' tells that between each sprite changing, the script will wait a bit - else, the animation will be too quick.
- The command 'alph' will set the transparency of an agent - 'alph integer yes/no' is the syntax of the command. (Note that this is a DS only command, and slow.)
- 'kill ownr' means that the owner of the script will be killed - here, the owner is the plant.
- In some agents, there might be a more complex route to take than the one we've chosen here of 'turn off the timer, grow, live, seed and die', but for this one, we're done. The endm marks the end of the timer script, as opposed to retn above, which closes off a subroutine.
- We will now make the timer of the seed
scrp 2 3 50000 9 wait rand 10 40 setv va00 posx setv va01 posy new: simp 2 4 50000 "sharmflower" 6 0 rand 200 6000 bhvr 32 attr 199 perm 40 emit 7 1 accg 3 elas 25 fric 90 aero 2 setv ov10 rand 200 1000 mvsf va00 va01 tick 60 kill ownr endm
You're finished! Congratulations. Enjoy your new plant agent.
- If you're going to add a push or pull script, try using a DOIF in the timer script to check the pose first off, before growing. Ghosthande has recommended using object variables to do so. As the timer script is interrupted by pushes and pulls, it is helpful to also build in a lifespan for your plant (official plants often used OV01 to do so).
- Alternatively, try using the ATTR with a DOIF to make the plant invisible unless it is at its mature pose.
- Try using the Constructor Script to hold various values for the plant and its seed.