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
Line 284: Line 284:
 
*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 and the number of images from the sprite file used in the [[NEW:SIMP]] line would both 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.
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 
[[Category:C3/DS CAOS]]
 
[[Category:C3/DS CAOS]]
 
[[Category:CCSF 2018]]
 
[[Category:CCSF 2018]]

Revision as of 04:21, 9 September 2018

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

 	  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.