Here's some example food - in the shape of cheese.
Code | Explanation |
********Lets make some Food * | This is a comment |
inst | Start with an inst - makes the rest of this part of code run in an instant |
*create some underneath the garden | This is a comment |
new: simp 2 11 1000 "infinite_cheese_machine" 2 44 5000 | Create a new object, with a classifier of 2 11 1000 (this family/genus combination marks the item as being a Food item). It will use the sprite file called 'infinite_cheese_machine' - BUT it will only use 2 images from this file starting at image number 44. Position the object at image plane 5000 |
attr 195 | Give it attributes that enable it to have gravity, boundaries and be picked up. |
bhvr 48 | Behaviour for the creature: creatures can perform pickup and eat on this object |
elas 30 | Slightly elastic - meaning it will bounce slightly when colliding with the floor |
fric 50 | Some friction - when placed on a slope it will slide for a while |
accg 3 | Moderate acceleration due to gravity |
mvto 1950 950 | Move to a suitable position |
cmrt 0 | Move the camera to point at it |
*****eat script | This is a comment |
scrp 2 11 1000 12 | Mark this script as being an eat script for all objects that have a classifier of 2 11 1000 |
lock | Lock the script - this means it cannot be interrupted by other scripts for this object, or by a creature trying to perform the same action in rapid succession |
sndc "chwp" | Play a sound effect |
stim writ from 79 1 | Send a stim to whoever triggered this event. This stim is the stim for eating food - it generally produces fat and protein in the receiving creature. |
pose 1 | Change pose |
wait 20 | wait for a little while (around a second) |
kill ownr | Kill the owning object - i.e. the piece of cheese that was eaten. |
endm | End of eat event script. |
********REMOVAL | This is a comment |
rscr | Marks this bit as a removal script |
enum 2 11 1000 | Enumerate across all the objects that match the classifier given (which in this case is our cheese) |
kill targ | Kill the current targ (which will be our cheese) |
next | Choose the next one that matches the classifier. |
This code will inject a single piece of cheese into the world - it isn't the same cheese that comes out of the Cheese Machine though. This cheese can only have one bite taken out of it, and once eaten will show an eaten frame for a second before removing itself from the world.
The advantage of using the genetic stims of a creature (the STIM command) rather than directly injecting chemicals is that you don't need to worry about what chemicals to inject, and in what amount. In this way all food will teach consistent lessons and have consistent effects. Another advantage is that each creature has the potential to have a different response to the object - because the genetics that define the response to that stim can differ among different creatures!Some projects that can be worked on with this code:
(1) Make the cheese supply multiple bites (for example, 5 bites before disappearing)
(2) Use your own graphics
(3) As well as doing a STIM, why not try injecting some other chemicals directly? A touch of alcohol may add a comedy walk to all who eat the cheese :-)