Welcome to the Creatures Wiki! Log in and join the community.

Difference between revisions of "Basic plant script"

From Creatures Wiki
Jump to navigation Jump to search
(46 intermediate revisions by 14 users not shown)
Line 1: Line 1:
 +
__NOTOC__
 
==Introduction==
 
==Introduction==
 +
[[File:Sharmflower.png|right|Sharmflower sprite images.]]
 +
Here is a very simple, base plant script which you can use for virtually any C3/DS [[plant]] [[agent]].
 +
It uses a few basic [[variable]]s.
  
Here is a very simple, base plant script which you can use for virtually any plant.
+
==The Install Script==
It uses a few basic variables, and a clever way of growing devised by [[nornagon]].
+
[[File:Sharmflower.png|right|thumb|Sharmflower sprite images, note that only the frames until the mature flower are used.]]
 
+
[[File:Sharmflower spritesheet.bmp|thumb|A [[Sprite#Spritesheets|spritesheet]] of the sharmflower suitable for import into SpriteBuilder.]]
 
+
*Create the plant!
*create the plant!
+
  new: simp 2 4 50000 "sharmflower" 6 0 rand 200 6000
  new: simp 2 4 50000 "basicplant" 3 0 rand 200 6000
 
  
 
But what does this mean?  
 
But what does this mean?  
*new: This means exactly what it says. New. Signifies the beginning of an install script, usually.
+
*[[new: simp]] - creates a new [[simple agent]]
*simp means that the agent is [[simple]], not [[complex]]
 
 
*2    is the [[family]]
 
*2    is the [[family]]
 
*4    is the [[genus]]; 4 = '''plant'''
 
*4    is the [[genus]]; 4 = '''plant'''
*50000 is the unique [[Classification system|classifier]]
+
*50000 is the [[species]]
*"basicplant" is the name of the image file which is situated in the images folder. So, this agent uses the image 'basicplant.c16'.
+
*"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|s16]] of the same name will be loaded).  See [[:File:Sharmflower.c16]] to download this file, or use the spritesheet above to the right with the blue border and use "Automatic Cut" after pasting it into [[SpriteBuilder]].
*3 is the number of images in the image 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 start image
+
*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.  
+
*[[RAND|rand]] 200 6000 sets the [[plane]] of the agent randomly from 200 to 6000.  
 +
 
 +
The next few parts set the object's properties.
 +
 
 +
[[BHVR]] 32
 +
[[ATTR]] 199
 +
perm 40
 +
emit 7 1
 +
[[ACCG]] 3
 +
[[ELAS]] 25
 +
fric 90
 +
[[AERO]] 2
 +
 
 +
*[[PERM|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|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|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"
  
Ok, the next few parts set the objects properties.
+
velo rand 10 25 rand 0 -10
  
bhvr 48
+
This will move the object to the Creator, whether it be the DS Agent Injector or the C3 Creator.
  
  attr 199
+
*[[MVSF|mvsf]] moves the current [[targ]] to a location on the map near the coordinates specified.
 +
*[[VELO|velo]] sets the velocity of the current targ. Agents move this distance in pixels (less the affect of air resistance, gravity, etc.) per tick.
 +
 
 +
[[TICK]] 60
 +
 
 +
*This is how often the [[timer script]] is called - this timer script is called every 3 seconds.
 +
 
 +
[[ENDM|endm]]
  
  perm 40
+
You've just finished the install script! Now, moving onto the next script...
  
emit 7 1
+
==The Timer Script==
  
  accg 3
+
  [[SCRP|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'
  
  elas 25
+
  [[TICK]] 0
  
  fric 90
+
*This makes it so that the timer script will run once, and then, never again. This can be useful as a resource-saving measure.
  
  aero 2
+
  gsub grow
 +
gsub live
 +
gsub seed
 +
gsub die
 +
 +
*[[GSUB|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|subr]]' "name of the subroutine" will begin the subroutine.
 +
*'[[RETN|retn]]' will end it.
  
*bhvr is the actions Creatures can perform on the object. A series of numbers signify different actions. IE, 1 means norns can activate the object. Then you add the numbers together, and in this case it equals 48.
+
*Now we're going to make the plant grow.
*attr is the attributes of the object. It works in the same way bhvr does, but in this case, the numbers signify gravity, whether the hand can activate it, and other things. In this case, it equals 199.
 
*perm is the permanency of the object. It goes from 0 to 100, 0 meaning that it can go through anything, such as walls etc, 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, its emitting plant smell.
 
*accg is the acceleration of an object as it falls down. Fairly obvious, really.
 
*elas is the elasticity of an object, as in, how much it bounces. This object bounces a bit, but not much. 0 is no bounce, 100 means it never stops bouncing.
 
*fric is the friction of an object, strangely enough. 0 means it doesn't move along the ground at all when thrown, 100 means it will continue sliding forever.
 
*aero is the aerodynamics of an object. (Better explanation needed here)
 
  
The next part is setting the variable we will use.
+
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|pose]]' defines the image used by the plant at the moment.
 +
*'[[SETV|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|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|repe]]', where 'X' is an integer
 +
*'[[WAIT|wait]] rand 40 80' means the script will wait randomly from 40 to 80 [[tick]]s. 
 +
*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.
  
  setv ov10 rand 200 1000
+
  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|loop]]' is the first part of the command which will make a part of script loop.
 +
*'[[DOIF|doif]] someting' means 'do only if the something is true' - a doif must be closed by '[[ENDI|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|subv]] va01 1' will subtract 1 from va01.
 +
*'endi' closes the 'doif' tag.
 +
*'[[UNTL|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.
  
In this object, ov10 is the lifespan of the plant. We're setting it randomly from 200 to 100. We'll see how to use this variable later.
+
*Now we've waited some time, and the plant has 'lived' enough to make seeds.
  
Almost done the install script! There is one more little chunk of code here.  
+
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|posx]]' and '[[POSY|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.
  
  mvsf game "CreatorX" game "CreatorY"
+
  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
  
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 is, in english, move to a place nearby thats safe. In this case, we want it to move to somewhere safe near the Creator.
+
*Note that this death script does not progress to the wilting frames.  The plant now grows backwards, from its adult pose to its seedling. 
*velo is the velocity the object appears with. This variable may look a little complicated, but in actuality is quite simple. (Better explanation needed here)
+
*'wait' tells that between each sprite changing, the script will wait a bit - else, the animation will be too quick.
 +
*The command '[[ALPH|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.
  
 
  endm  
 
  endm  
 +
*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.
  
You've just finished the install script! Congratulations! Now, moving onto the next script..
+
*We will now make the timer of the seed
  
==The Timer Script==
+
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
  
Coming soon..
+
You're finished!  Congratulations. Enjoy your new plant agent.
  
 +
==Moving on==
 +
*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 [http://creaturescaves.com/dev.php?section=Advice&view=3469 recommended] using [[object variables]] to do so.  As the timer script is interrupted by pushes and pulls, it is helpful to also [http://www.gamewareeurope.com/GWDev/cdn/cdn_more.php?CDN_article_id=7 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.
 +
*Check the [[RTYP|room type]] before creating a seed.
 +
*Use [[RNGE]] and [[ESEE]], as seen in [https://creaturescaves.com/community.php?section=Resources&view=97 Making a Smart Vendor], to manage the population of your plants.
  
[[Category:Tutorials]]
+
==See also==
 +
*[[Basic interactive plant script]] - uses another approach to handle the growth and allows for [[stimuli]] to be felt by creatures.
 +
 +
[[Category:Tutorials]][[Category:C3/DS CAOS]]

Revision as of 23:03, 15 February 2020

Introduction

Sharmflower sprite images.

Here is a very simple, base plant script which you can use for virtually any C3/DS plant agent. It uses a few basic variables.

The Install Script

Sharmflower sprite images, note that only the frames until the mature flower are used.
A spritesheet of the sharmflower suitable for import into SpriteBuilder.
  • 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, or use the spritesheet above to the right with the blue border and use "Automatic Cut" after pasting it into SpriteBuilder.
  • 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.

BHVR 32
ATTR 199
perm 40
emit 7 1
ACCG 3
ELAS 25
fric 90
AERO 2
  • 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.
TICK 60
  • This is how often the timer script is called - this timer script is called every 3 seconds.
endm

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'
TICK 0
  • 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.
endm 
  • 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.

Moving on

See also