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
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__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]].
 
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.
 
It uses a few basic [[variable]]s.
  
 
==The Install Script==
 
==The Install Script==
 
+
[[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 "basicplant" 3 0 rand 200 6000
+
  new: simp 2 4 50000 "sharmflower" 6 0 rand 200 6000
  
 
But what does this mean?  
 
But what does this mean?  
Line 15: Line 16:
 
*4    is the [[genus]]; 4 = '''plant'''
 
*4    is the [[genus]]; 4 = '''plant'''
 
*50000 is the [[species]]
 
*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]]'. (Although, if no c16 is found, an [[.s16|s16]] of the same name will be loaded).
+
*"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 the plant can use.
+
*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).
 
*0 is the image number to start counting these from (So, 2 3 would give the plant 2 images, 3 and 4).
 
*[[RAND|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.  
Line 39: Line 40:
 
  [[setv]] ov10 rand 200 1000
 
  [[setv]] ov10 rand 200 1000
  
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.
+
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.  
 
Almost done with the install script! There is one more little chunk of code here.  
Line 53: Line 54:
  
 
  [[TICK]] 60
 
  [[TICK]] 60
 +
 +
*This is how often the [[timer script]] is called - this timer script is called every 3 seconds.
 +
 
  [[ENDM|endm]]
 
  [[ENDM|endm]]
  
Line 83: Line 87:
 
  subr grow
 
  subr grow
 
  setv va00 pose
 
  setv va00 pose
  reps 2
+
  reps 5
 
  wait rand 40 80
 
  wait rand 40 80
 
  addv va00 1
 
  addv va00 1
Line 91: Line 95:
 
   
 
   
 
*As said before, 'subr grow' opens the subroutine - here the name is 'grow', but you can use any name you want.
 
*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 3 images, and the base image is 0.
+
*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.
 
*'[[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.
 
*'[[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]] 2' means that the lines which are following will be repeated twice.
+
*'[[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
 
*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.   
 
*'[[WAIT|wait]] rand 40 80' means the script will wait randomly from 40 to 80 [[tick]]s.   
Line 100: Line 104:
 
*Now we can set the pose to va00 : 'pose va00' means : set the pose to the number contained in va00.
 
*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.
 
*'repe' : this is the closing tag of the 'reps' command.
*The pose changing is repeated twice, because we want to move from pose 0 to pose 2
+
*The pose changing is repeated five times, because we want to move from pose 0 to pose 5
 
*'retn' closes the subroutine.   
 
*'retn' closes the subroutine.   
  
Line 123: Line 127:
 
*'[[UNTL|untl]] something' is the closing tag of the 'loop' command - the script will loop until the condition 'something' won't be true.
 
*'[[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.
 
*Here the script will loop until ov10 is equal to 100.
*'retn' closes the subroutine .
+
*'retn' closes the subroutine.
  
 
*Now we've waited some time, and the plant has 'lived' enough to make seeds.
 
*Now we've waited some time, and the plant has 'lived' enough to make seeds.
Line 139: Line 143:
 
  mvsf va10 va11
 
  mvsf va10 va11
 
  velo rand -10 10 rand -10 0
 
  velo rand -10 10 rand -10 0
  tick 1
+
  tick 5
 
  targ ownr
 
  targ ownr
 
  repe
 
  repe
Line 166: Line 170:
 
  kill ownr
 
  kill ownr
 
  retn
 
  retn
endm
 
  
*The plant now grows backwards, from its adult pose to its seedling.
+
 
 +
 
 +
*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.
 
*'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.''')
 
*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.
 
*'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
 
*We will now make the timer of the seed
Line 179: Line 187:
 
  setv va00 posx
 
  setv va00 posx
 
  setv va01 posy
 
  setv va01 posy
  new: simp 2 4 50000 "basicplant" 3 0 rand 200 6000
+
  new: simp 2 4 50000 "sharmflower" 6 0 rand 200 6000
 
  bhvr 32
 
  bhvr 32
 
  attr 199
 
  attr 199
Line 190: Line 198:
 
  setv ov10 rand 200 1000
 
  setv ov10 rand 200 1000
 
  mvsf va00 va01
 
  mvsf va00 va01
  tick 1
+
  tick 60
 
  kill ownr
 
  kill ownr
 
  endm
 
  endm
  
 
You're finished!  Congratulations.  Enjoy your new plant agent.
 
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.
 +
 +
==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]]
 
[[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