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

Difference between revisions of "Basic interactive plant script"

From Creatures Wiki
Jump to navigation Jump to search
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
This is a CAOS tutorial in the form of an in-depth analysis of an agent.
 +
 
__NOTOC__
 
__NOTOC__
 
==Introduction==
 
==Introduction==
Line 6: Line 8:
 
==CAOS2PRAY==
 
==CAOS2PRAY==
 
[[File:Monk.png|right|Monk, ready to use CAOS2PRAY.]]
 
[[File:Monk.png|right|Monk, ready to use CAOS2PRAY.]]
CAOS2PRAY is a feature included with [[User:RProgrammer|RProgrammer]]'s [[Jagent]] which allows the coder to not have to code a separate PRAY file in their agents.  This chunk of code goes at the top of the COS file, and when it is dragged and dropped onto Monk, compiles the cos file, with its dependant sprite file, into an agent that will be easy for everyone to install and play with.  For more details on CAOS2PRAY, see [https://naturingnurturing.blogspot.com/2012/01/caos2pray-easier-way.html CAOS2PRAY: An Easier Way] by [[Amaikokonut]].
+
CAOS2PRAY is a feature included with [[User:RProgrammer|RProgrammer]]'s [[Jagent]] which allows the coder to not have to code a separate [[PRAY source|PRAY file]] in their agents.  This chunk of code goes at the top of the COS file, and when it is dragged and dropped onto Monk, compiles the cos file, with its dependant sprite file, into an agent that will be easy for everyone to install and play with.  For more details on CAOS2PRAY, see [https://naturingnurturing.blogspot.com/2012/01/caos2pray-easier-way.html CAOS2PRAY: An Easier Way] by [[Amaikokonut]].
  
 
   **CAOS2PRAY
 
   **CAOS2PRAY
Line 22: Line 24:
 
==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.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.]]
  
 
   inst   
 
   inst   
Line 29: Line 32:
 
   reps 5   
 
   reps 5   
  
[[NEW: SIMP]] line, installing a plant with the [[class number]] 2 4 1000, using the first 5 images in the sprite named [[:File:Sharmflower.c16]], and installing it in a random [[plane]] between 200 and 6000.
+
[[NEW: SIMP]] line, installing a plant with the [[class number]] 2 4 1000, using the first 6 images in the sprite named [[:File:Sharmflower.c16]], and installing it in a random [[plane]] between 200 and 6000.  A [https://web.archive.org/web/20050312122959/http://www.freewebs.com/alimaggs/creaturesdev/cdn/c3/knowledgebase/c3_errors.html common error] that can be introduced here is "Pose change failed", caused by miscounting the amount of images that are being used, by not including image #0.  An alternative to using the .c16 provided is to use the spritesheet above to the right with the blue border and use "Automatic Cut" after pasting it into [[SpriteBuilder]].
  
     new: simp 2 4 1000 "sharmflower" 5 0 rand 200 6000   
+
     new: simp 2 4 1000 "sharmflower" 6 0 rand 200 6000   
  
 
Various attributes: note that it cannot be picked up by the hand.  [[Amaikokonut]]'s [http://songua.com/creatures/caosapps/ CAOS APPS] can be used to help choose new ATTR and BHVR values.  
 
Various attributes: note that it cannot be picked up by the hand.  [[Amaikokonut]]'s [http://songua.com/creatures/caosapps/ CAOS APPS] can be used to help choose new ATTR and BHVR values.  
Line 40: Line 43:
  
 
     [[bhvr]] 11   
 
     [[bhvr]] 11   
 
 
     [[elas]] 0   
 
     [[elas]] 0   
  
Line 55: Line 57:
 
     [[tick]] rand 200 1000   
 
     [[tick]] rand 200 1000   
  
Using [[TMVT]] and a [[DOIF]]-[[ENDI]] to test whether it can move into the C3 norn terrarium
+
Using [[TMVT]] and a [[DOIF]]-[[ENDI]] to test whether it can move into the C3 norn terrarium, choosing a random X-location between 1740 and 2740, but a constant Y-location (674) to move to.
  
 
     doif tmvt [[rand]] 1740 2740 674 eq 1   
 
     doif tmvt [[rand]] 1740 2740 674 eq 1   
 
 
     [[mvto]] rand 1740 2740 674   
 
     [[mvto]] rand 1740 2740 674   
 
 
     endi   
 
     endi   
  
Line 95: Line 95:
 
     doif ov00 eq 0   
 
     doif ov00 eq 0   
  
This uses a temporary variable to step up through the poses if it is less than 5, the mature flower.
+
This uses a temporary variable ([[VAxx|va00]]) to step up through the poses if it is less than 5, the mature flower.
  
 
     doif [[POSE|pose]] lt 5   
 
     doif [[POSE|pose]] lt 5   
 
 
     setv va00 pose   
 
     setv va00 pose   
 
 
     [[addv]] va00 1   
 
     [[addv]] va00 1   
 
 
     pose va00   
 
     pose va00   
 
 
     else   
 
     else   
  
Line 142: Line 138:
  
 
   setv va00 pose   
 
   setv va00 pose   
 
 
   [[subv]] va00 1   
 
   [[subv]] va00 1   
 
 
   pose va00   
 
   pose va00   
  
Line 153: Line 147:
 
Reset the age counter and the plant state, ready for the next growth cycle.
 
Reset the age counter and the plant state, ready for the next growth cycle.
 
 
     setv ov99 0
+
     setv ov99 0  
 
 
 
     setv ov00 0   
 
     setv ov00 0   
  
Line 167: Line 160:
 
end the timer script.
 
end the timer script.
  
   endm
+
   endm
  
 
==The Hit Script==
 
==The Hit Script==
Line 209: Line 202:
 
   inst
 
   inst
 
   reps 5
 
   reps 5
new: simp 2 4 1000 "sharmflower" 5 0 rand 200 6000
+
new: simp 2 4 1000 "sharmflower" 6 0 rand 200 6000
 
attr 192
 
attr 192
 
bhvr 11
 
bhvr 11
Line 283: Line 276:
 
scrx 2 4 1000 2
 
scrx 2 4 1000 2
 
scrx 2 4 1000 9
 
scrx 2 4 1000 9
scrx 2 4 1000 3</pre>
+
scrx 2 4 1000 3</pre>
  
 
==Moving On==
 
==Moving On==
 
*Change the [[genus]] to be a [[bad plant]] (2 '''5''' 1000 instead of 2 4 1000) and change all three [[stimuli]] to '''83''', "Danger plant", instead of 84, "Friendly plant".   
 
*Change the [[genus]] to be a [[bad plant]] (2 '''5''' 1000 instead of 2 4 1000) and change all three [[stimuli]] to '''83''', "Danger plant", instead of 84, "Friendly plant".   
  
*Make the plant appear in a different metaroom by using the [[Keyboard Shortcuts|keyboard shortcut CTRL + SHIFT + X]] to explore different coordinates.
+
*[http://creaturescaves.com/dev.php?section=Reservations Reserve] and use your own [[class number]]s at [[Creatures Caves]].
 +
 
 +
*Search on [[OpenGameArt.org]] or take inspiration from the [[Creating Agent Art]] tutorial to make a new [[sprite]] for your plant.
 +
 
 +
*Make the plant appear in a different metaroom.  Use the [[Keyboard Shortcuts|keyboard shortcut CTRL + SHIFT + X]] to explore different coordinates.
  
 
*Try using the [[Constructor Script]] (10) to hold various values for the plant.
 
*Try using the [[Constructor Script]] (10) to hold various values for the plant.
  
*To simulate ungrowing to death, an additional, [[wikipedia:Shades_of_black#Black|pure black]], sprite could be added to [[:File:Sharmflower.c16|the C16 file]] as sprite #0 to allow the plant to vanish, and the number used to note the peak of the plant's growth would also need to be changed.
+
*To simulate ungrowing to death, an additional, [[wikipedia:Shades_of_black#Black|pure black]], sprite could be added to [[:File:Sharmflower.c16|the C16 file]] as sprite #0 to allow the plant to vanish, and the number used to note the peak of the plant's growth and the number of images from the sprite file used in the [[NEW: SIMP]] line would both need to be changed.
 +
 
 +
*See [[Basic interactive plant script part 2]]
 +
 
 +
*See the [[fungi]].cos fruit timer script (scrp 2 8 5 9) for an object that uses similar logic statements to grow, wait and then grow old and die, rather than grow and ungrow forever as this example plant does. 
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 
[[Category:C3/DS CAOS]]
 
[[Category:C3/DS CAOS]]
 
[[Category:CCSF 2018]]
 
[[Category:CCSF 2018]]

Revision as of 20:31, 26 November 2019

This is a CAOS tutorial in the form of an in-depth analysis of an agent.


Introduction

Sharmflower sprite images.

This plant script uses a few basic variables and is coded so that creatures can push, pull or hit the plant, with the appropriate stimulus attached, so that creatures are rewarded for playing with plants. The plant itself will grow and ungrow wherever it lands, and never die. Unlike the basic plant script, this plant's growth script does not use subroutines, and instead, relies on valid logic statements to give another approach to solving the problems associated with growing plants with CAOS. It's useful to use the CAOS Tool or another highlighting tool because they can make the CAOS syntax easier to read.

CAOS2PRAY

Monk, ready to use CAOS2PRAY.

CAOS2PRAY is a feature included with RProgrammer's Jagent which allows the coder to not have to code a separate PRAY file in their agents. This chunk of code goes at the top of the COS file, and when it is dragged and dropped onto Monk, compiles the cos file, with its dependant sprite file, into an agent that will be easy for everyone to install and play with. For more details on CAOS2PRAY, see CAOS2PRAY: An Easier Way by Amaikokonut.

 **CAOS2PRAY
 *# Pray-File "BasicInteractivePlant.agents"
 *# C3-Name "Basic Interactive Plant"
 *# attach sharmflower.c16
 *# desc = "A basic plant that grows and ungrows, and creatures can interact with.  Injects into the C3 Norn Terrarium."
 *# Agent Animation File = "sharmflower.c16"
 *# Agent Animation String = "0 1 2 3 4 5 4 3 2 1 255"
 *# Agent Sprite First Image = 0
 *# Agent Animation Gallery = "sharmflower"
 *# Web URL = "creatures.wiki"
 *# Web Label = "Creatures Wiki"

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.
 inst  

Install 5 in the C3 Norn Terrarium using a REPS and REPE loop.

 reps 5  

NEW: SIMP line, installing a plant with the class number 2 4 1000, using the first 6 images in the sprite named File:Sharmflower.c16, and installing it in a random plane between 200 and 6000. A common error that can be introduced here is "Pose change failed", caused by miscounting the amount of images that are being used, by not including image #0. An alternative to using the .c16 provided is to use the spritesheet above to the right with the blue border and use "Automatic Cut" after pasting it into SpriteBuilder.

 	  new: simp 2 4 1000 "sharmflower" 6 0 rand 200 6000  

Various attributes: note that it cannot be picked up by the hand. Amaikokonut's CAOS APPS can be used to help choose new ATTR and BHVR values.

 	  attr 192  

BHVR is 11, meaning it can be pushed, pulled and hit, aspiring to AquaShee's Creatures Development Standards project.

 	  bhvr 11  
 	  elas 0  

OV00 - Plant state: an object variable (OV) which we're using to tell the plant to switch between growing UP and growing DOWN

 	  setv ov00 0  

OV99 - an object variable we're going to use as an age counter, counts the amount of time spent in a mature state.

   	setv ov99 0  

The timer script will run every 10 to 50 in-game seconds.

 	  tick rand 200 1000  

Using TMVT and a DOIF-ENDI to test whether it can move into the C3 norn terrarium, choosing a random X-location between 1740 and 2740, but a constant Y-location (674) to move to.

 	  doif tmvt rand 1740 2740 674 eq 1  
 		  mvto rand 1740 2740 674  
 	  endi  

Ending the '5 plants' REPS loop

   repe

The Push Script

 scrp 2 4 1000 1  

Stimulating the creature who pushed the plant with stimulus # 84: played with friendly plant.

 	  stim writ from 84 1  
 endm  

The Pull Script

 scrp 2 4 1000 2  

Stimulating the creature who pulled the plant with stimulus # 84: played with friendly plant.

 	  stim writ from 84 1  
 endm  

The Timer Script

Sharmflower sprite images.

Just as a reminder, this will run at a random point between 10 to 50 seconds. This timer script does not use subroutines, and relies on valid logic statements.

 scrp 2 4 1000 9  

ov00 is the plant state: whether it is growing UP or down. If ov00 is 0, the plant will grow UP.

   	doif ov00 eq 0  

This uses a temporary variable (va00) to step up through the poses if it is less than 5, the mature flower.

   		doif pose lt 5  
   			setv va00 pose   
   			addv va00 1   
   			pose va00  
   		else   

Because the state (ov00) is growing UP, but the pose of the plant is NOT less than 5, the plant must be mature, so adding to its age counter (ov99) allows it to remain in a mature pose.

 	  		addv ov99 1   

End the check if the plant's pose is less than mature.

 		  endi  

Check how long we've been mature and counting up the age counter (ov99): if it's equal to 50, the plant has been mature for too long now, prepare to become immature.

 		  doif ov99 eq 50  

Setting the state (ov00) to 1 to signal that the plant is now growing down.

 		  	setv ov00 1   

Ending the age check (ov99) for the plant.

 		  endi  

Ending the check if the state (ov00) is 0.

 	  endi  

If the state (ov00) is 1,

   	doif ov00 eq 1   

and if the pose is greater than 0

   		doif pose gt 0  

Subtract 1 from the pose.

  			setv va00 pose  
  			subv va00 1   
  			pose va00   

If the pose is not greater than 0 (then it must be 0)

  		else   

Reset the age counter and the plant state, ready for the next growth cycle.

   setv ov99 0 
   			setv ov00 0  

end the pose check

  		endi  

end the state check

 	  endi  

end the timer script.

 endm

The Hit Script

This script reuses two pieces of code from previous scripts: it stimulates whoever hit the plant as per the push script, and it uses a bit of code repeated from the timer to make the plant grow down if it is hit when it is more than just a seedling. Note the use of TARG OWNR between the two to make sure that the plant itself will change pose.

 scrp 2 4 1000 3
 	stim writ from 84 1 
 	targ ownr
 	doif pose gt 0 
 	setv va00 pose
 		 subv va00 1
 	pose va00
 	endi
 	endm  

The Removal Script

This simply counts through all the objects in the world with that class number, removes them, and then removes the scripts that belong to that class number. It's important to double-check that the class numbers here match the class numbers you've been using all along, and make sure that all SCRPs in the object have a corresponding scrx. If the class numbers here do not match the ones you've been using, you might accidentally delete some other object in the player's world, or silently delete another object's scripts, which would be hard for someone to fix!

 rscr
 enum 2 4 1000
 	kill targ
 next
 scrx 2 4 1000 1
 scrx 2 4 1000 2
 scrx 2 4 1000 9
 scrx 2 4 1000 3  

Whole script

  **CAOS2PRAY
  *# Pray-File "BasicInteractivePlant.agents"
  *# C3-Name "Basic Interactive Plant"
  *# attach sharmflower.c16
  *# desc = "A basic plant that grows and ungrows, and creatures can interact with.  Injects into the C3 Norn Terrarium."
  *# Agent Animation File = "sharmflower.c16"
  *# Agent Animation String = "0 1 2 3 4 5 4 3 2 1 255"
  *# Agent Sprite First Image = 0
  *# Agent Animation Gallery = "sharmflower"
  *# Web URL = "creatures.wiki"
  *# Web Label = "Creatures Wiki" 

  inst
  reps 5
	new: simp 2 4 1000 "sharmflower" 6 0 rand 200 6000
	attr 192
	bhvr 11
	elas 0
	setv ov00 0
	setv ov99 0
	tick rand 200 1000
	doif tmvt rand 1740 2740 674 eq 1
		mvto rand 1740 2740 674
	endi
repe

*push script
scrp 2 4 1000 1
	stim writ from 84 1
endm

*pull script
scrp 2 4 1000 2
	stim writ from 84 1
endm

*timer script
scrp 2 4 1000 9
*Grow UP
	doif ov00 eq 0
		doif pose lt 5
			setv va00 pose
			addv va00 1
			pose va00
		else
*remain in a mature pose, add to age counter.		
			addv ov99 1
		endi
*you've been mature for too long now, prepare to become immature.	
		doif ov99 eq 50
			setv ov00 1
		endi
	endi
*grow DOWN	
	doif ov00 eq 1
		doif pose gt 0
			setv va00 pose
			subv va00 1
			pose va00
		else
*Reset plant		
			setv ov99 0
			setv ov00 0
		endi
	endi
endm

*Hit script
scrp 2 4 1000 3
	stim writ from 84 1
*this makes sure that the plant itself is targeted to change pose.	
	targ ownr
*the plant grows DOWN if it is hit.	
	doif pose gt 0
		setv va00 pose
		subv va00 1
		pose va00
	endi
endm

*REMOVE ME
rscr
enum 2 4 1000
	kill targ
next
scrx 2 4 1000 1
scrx 2 4 1000 2
scrx 2 4 1000 9
scrx 2 4 1000 3

Moving On

  • Change the genus to be a bad plant (2 5 1000 instead of 2 4 1000) and change all three stimuli to 83, "Danger plant", instead of 84, "Friendly plant".
  • To simulate ungrowing to death, an additional, pure black, sprite could be added to the C16 file as sprite #0 to allow the plant to vanish, and the number used to note the peak of the plant's growth and the number of images from the sprite file used in the NEW: SIMP line would both need to be changed.
  • See the fungi.cos fruit timer script (scrp 2 8 5 9) for an object that uses similar logic statements to grow, wait and then grow old and die, rather than grow and ungrow forever as this example plant does.