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

Difference between revisions of "KAOS How To"

From Creatures Wiki
Jump to navigation Jump to search
m
Line 341: Line 341:
 
if (owner.stage_of_life==0) {owner.baseIndex=0;framerate(3); a.anim(4);}
 
if (owner.stage_of_life==0) {owner.baseIndex=0;framerate(3); a.anim(4);}
 
  if (owner.stage_of_life==1) {owner.baseIndex=0;framerate(3); a.anim(5,4);}
 
  if (owner.stage_of_life==1) {owner.baseIndex=0;framerate(3); a.anim(5,4);}
  if (owner.stage_of_life==9 || owner.stage_of_life==10)  {a.baseIndex=0;framerate(5);<br /> a.anim(49,39,29,19,9,8,7,6,5,4);}
+
  if (owner.stage_of_life==9 || owner.stage_of_life==10)  {a.baseIndex=0;framerate(5);  
 +
                                                                                                  a.anim(49,39,29,19,9,8,7,6,5,4);}
 
kill(a);
 
kill(a);
 
}
 
}

Revision as of 09:13, 21 June 2009

Editnorn.png This article is about a project that is in development.
Information may change significantly as the project progresses.

Install

I presume you have some basic knowlage, of inner caos-working,c16-image-editor,folders , about agents etc.

  • Linux : Download kaos_1.tar.bz2 , untar and copy kaos and mach.sh in /usr/local/bin.
  • Win(XP) : Download installer, at c:\programme\kaos is batch-file run_kaos.bat, copy this in workingdir. then type :run_kaos foo.k

Whats new

My version runs with the normal Linux Creatures Evolution Engine, if the cos-files are put in Bootstrap-folder. The Numbers of script command could now be up to 65535.

The big advantage of kaos is : the scripts are more readable and modern as caos .

My precompiled version of kaos-compiler includes the following libraries:

attrbhvr.k
prelude.k
KaosLib.k
lib2.k

In these libraries most commands for everyday use of caos are defined. If you need a new command or macro write an include file and bind it to your source. You should only to recompile if you have a lot of libraries for everyday use.

How to use

Simply take a text editor (geany would be perfect , I am planning some extensions), write code and save file with a .k file extension. Then type mach.sh foo.k , output is saved as foo.k.cos.

For using newcompound(), in my way first you have to define the variables:

...
define numeric F_INVISIBLE = 1 ;define numeric G_SYSTEM = 1 ; ...
...
newcompound(F_INVISIBLE, G_SYSTEM, S_SIMPLEMONITOR, "ds gui", 77,2, 5000);
...

or you write an extra file with predefined constants. see classifiers.k

This allows you to build an table for multiple use without looking for Classification system all time.

For other constants see e.g. predef.k (these are the same used by Docking Station ov01,ov02... for agents)

To define new commands make new file e.g. mylib.k and then

...
#include my.lib 
#include classifiers.k 
#include predef.k 
...

NOTE : the includes Should BE AT THE TOP OF THE FILE (an preprocesso writen in haskell does the work)

How to write a new kaos command

This is simple . See first in doc/index.html if the command is already defined.

For agent independent commands: You need for example HAND, which is define in CAOS-handbook as:

HAND (command) name_for_the_hand (string)
 Sets the name of the hand. By default this is 'hand'.
HAND (string)
 This returns the name of the hand.

The first is a value assignment, the second returns the assigned value.

To define a new kaoscommand, type :

 /**First:
 HAND string
 */
 define new_name_of_hand(string name) /* could be string numeric or agent */ {

	_caos { HAND $name(r);

	}

 }

then you could use later : new_name_of_hand("Norn"); /* same type as definition*/ => HAND Norn

/**Second:
HAND returning string
 */
define whats_your_name() returning string  /* could be string numeric or agent */ {

	     _caos { .static let $return = HAND; };

}; 

usage : string c = whats_your_name(); prints(c); /* must be the same type as in definition prints is debug*/ =>dbg: outs hand

For agent related commands, e.g. VELO:

/**
VELO
*/
define velocity( agent a,numeric x, numeric y)
{
  _caos {
    .targ < $a {
      VELO $x(r) $y(r);
    };
  };
}

usage : velocity(a,(20),0); or a.velocity((-20),0); ( where a is agent), both mean the same => VELO 20 0

A little demo-agent

First lets start easy . A moving window at the left side of the main screen, which shows the x,y position of mouse-pointer (hand).
Comments are the same as c,c++

  • one line to end //
  • multiline /* ..... */

If keywords are used (inside the comment lines) e.g. Script, File, Function... , then it is possible to generate with NaruralDocs auto-documents.


/**
    Script: simplemonitor
    ___________________________________________________________________________

    Version 0.1
    Copyright (C) 2008 august0815
   * under GNU
 * -----------------------------------------------------------------------------
 * Agent  : F_INVISIBLE, G_SYSTEM, S_SIMPLEMONITOR
 * Sprites: ds gui ( orginal dockingstation sprites)
 * -----------------------------------------------------------------------------
 */

now the included files:(with constants,predefs...). To download see : [1]

#include classifiers.k 
#include predef.k 

This is how to access OV-Varioables :here OV99 Note must be at top BEFORE install begins!!

ovar numeric hidden[99];//true=1 false =0

The basic-funktions of agents are install{}, script{} ,remove{}
it is not necessary to put all in one file but more readable.

Inside install{} all information about attributes , images are written it is the same as INST in caos!

install {
        agent simplemonitor;
      	simplemonitor = newcompound(F_INVISIBLE, G_SYSTEM, S_SIMPLEMONITOR, "ds gui", 77,2, 5000);
      	simplemonitor.attributes = A_CAMERASHY|A_FLOATABLE|A_INVISIBLE;;
        simplemonitor.floatat(-331, 400);
        simplemonitor.tick = 2;
        simplemonitor.hidden=1;
      	simplemonitor.newtextinputpart(1, "ds gui", 4, 100, 100, 0, 0, "whiteontransparentchars");
        simplemonitor.changepart(1);
		simplemonitor.textformat(1 ,1, 1, 1, 1, 1, 0);	
		simplemonitor.newtextinputpart(2, "ds gui", 4, 100, 135, 0, 0, "whiteontransparentchars");
        simplemonitor.changepart(2);
		simplemonitor.textformat(1 ,1, 1, 1, 1, 1, 0);	
		simplemonitor.newbutton(3, "ds gui", 14, 77, 331, 0,  0 ,"[]", 2000, 1);
		simplemonitor.newbutton(4, "ds gui", 16, 77, 331, 170,  0 ,"[]", 2001, 1);
     }

This is the same as SCRP

 
script (F_INVISIBLE, G_SYSTEM, S_SIMPLEMONITOR,2000) {agent a=owner;
 if (a.hidden==0) {velocity(a,(-20),0);wait(15);velocity(a,(0),0);}
 a.hidden=1;
  }
script (F_INVISIBLE, G_SYSTEM, S_SIMPLEMONITOR,2001) {agent a=owner;
 if (a.hidden==1) { velocity(a,(20),0);wait(15);velocity(a,(0),0);}
 a.hidden=0;
  }     
script ( F_INVISIBLE, G_SYSTEM, S_SIMPLEMONITOR, 9) {
	agent s;s=owner;numeric room;numeric x;numeric y;numeric type;string fo;numeric foo;string fooo;
	string ausgabe="Room ";numeric xx;numeric yy;
	s.changepart(1);
	room=getroomid(mouseX(),mouseY());
        ausgabe="X:  " ;
        xx = pointer.x;
        ausgabe=addstring(ausgabe,NumToStr(xx));
        s.parttext=ausgabe;
	s.changepart(2); 
        ausgabe="Y:  " ;
        yy = pointer.y;
        ausgabe=addstring(ausgabe,NumToStr(yy));
        s.parttext=ausgabe;
}

The RSCR

remove {
     enum (F_INVISIBLE, G_SYSTEM, S_SIMPLEMONITOR) {|p| p.kill();}
	// Zap the scripts.
	deletescript( F_INVISIBLE, G_SYSTEM, S_SIMPLEMONITOR,9);
}

Reimplement of orange sponge.cos from C3

Analyse of Orange Sponge.cos from C3


First look at the cos script. The agent has only one script :timer! The Subs I want to port to define macros.


Main script

/**
    Script: orang.k
    ___________________________________________________________________________
    Version 0.1
    Copyright (C) 2009 august0815
   * under GNU
 * -----------------------------------------------------------------------------
 * Agent  : F_INVISIBLE, G_GOODPLANT, S_ORA
 * Sprites: oraponge.c16 //form C3 
 * -----------------------------------------------------------------------------
 */
/* Save this as orang.k  an compile with run_kaos.sh orang.k (run_kaos.bat orang.k ) */
// include files must be in the same folder  !!
define numeric F_INVISIBLE = 1 ;
define numeric G_GOODPLANT = 4;
define numeric S_ORA =3002;
define numeric S_ORA_SEED=3003;
#include predef.k 

#include mymacro.k 

ovar numeric temp40[40];

install {
numeric ypos=9500; // in DS meso
numeric xpos=1250; // in DS meso
numeric t=0;
do{
t=t+1;
        agent opal;numeric x,y,z;
      	opal = newcompound(F_INVISIBLE, G_GOODPLANT, S_ORA,"oraponge", 59 ,0 ,4200);
      	opal.attributes=197;
		opal.perm=100;
		opal.elasticity=0;
		opal.clickAction=(-1);
		opal.acceleration=1;
		opal.aerodynamics=5;
		opal.friction=100;
		opal.pose=4;
		x=(t*20)+1250;//xops
		 	
      	opal.moveto(x,ypos); 
      	opal.age_of_agent=399;
		opal.stage_of_life=8;
		opal.bioenergy=55;
		opal.tick=10;
	} while t<2
}
script ( F_INVISIBLE, G_GOODPLANT, S_ORA, 9) {agent a=owner; numeric randval;
   a.age_of_agent=a.age_of_agent+1;
   if (roomOfTarg(a)==9) {deth2(a);}//NOT IN WATER :)
   
   if (a.age_of_agent>700) {deth2(a);}
   if ((a.age_of_agent>0) && (a.age_of_agent<25)) {a.pose=4; a.stage_of_life=0;};
   if ((a.age_of_agent>=25) && (a.age_of_agent<75) && (a.stage_of_life==0) ) {a.pose=5; a.stage_of_life=1;};
   if ((a.age_of_agent>=75) && (a.age_of_agent<100)&& (a.stage_of_life==1)) {a.pose=6; a.stage_of_life=2;};
   if ((a.age_of_agent>=100) && (a.age_of_agent<150) && (a.stage_of_life==2)) {a.pose=7; a.stage_of_life=3;};
   if ((a.age_of_agent>=150) && (a.age_of_agent<200) && (a.stage_of_life==3)) {a.pose=8; a.stage_of_life=4;};
   if ((a.age_of_agent>=200) && (a.age_of_agent<250) && (a.stage_of_life==4)) {a. baseIndex=9; a.stage_of_life=5;};//set base 9
   if ((a.age_of_agent>=250) && (a.age_of_agent<300) && (a.stage_of_life==5)) {a. baseIndex=19; a.stage_of_life=6;};
   if ((a.age_of_agent>=300) && (a.age_of_agent<350) && (a.stage_of_life==6)) {a. baseIndex=29; a.stage_of_life=7;};
   if ((a.age_of_agent>=350) && (a.age_of_agent<400) && (a.stage_of_life==7)) {a. baseIndex=39; a.stage_of_life=8;};
   if ((a.age_of_agent>=400) && (a.age_of_agent<450) && (a.stage_of_life==8)) {a. baseIndex=49; a.stage_of_life=9;};

   if ((a.stage_of_life>4) && (a.stage_of_life<10) ) {a.anim(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255);};
   
   if (a.age_of_agent>700) {kill(a);}/* {deth2(a);}*/; //is needed?
   
   if ((a.stage_of_life>0) || (a.stage_of_life<2) ) {check(a);};
   
   if (a.stage_of_life==10) { a.temp40=a.temp40+1;
   								if (a.temp40==20) {a.stage_of_life=9;}
   							}	
 
	
	if (a.stage_of_life==9)  {randval=getRandom(1,20); if (randval=10) {seed();} };
	
  }

  
 script ( F_INVISIBLE, G_GOODPLANT, S_ORA_SEED, 9) {agent a=owner;
 		if (a.stats==0) { whatroom(a); a.age_of_agent=a.age_of_agent+2;
 			if ((a.tmp==99) || (a.age_of_agent>1500)) {deth (a);}
 			if ((a.age_of_agent>1000) && (a.age_of_agent<1500)) {a.acceleration=0.50;a.stats=1;/*wait 75? */}
 			a.anim(0, 1, 2, 3, 255);
			} 
 		if (a.stats!=0)	{ grow(a);}	/* and not carr!!*/
 		rndm(a);
 		move_it(a);
 		a.velocity (a.x_heading,a.y_heading);
}

remove {
     enum ( F_INVISIBLE, G_GOODPLANT, S_ORA) {|p| p.kill();}
     enum ( F_INVISIBLE, G_GOODPLANT, S_ORA_SEED) {|p| p.kill();}    
	// Zap the scripts.
	deletescript(  F_INVISIBLE, G_GOODPLANT, S_ORA,9);
	deletescript(F_INVISIBLE, G_GOODPLANT ,S_ORA_SEED,9);
}

mymacro.k for plant

ovar numeric tmp[99];
ovar numeric temp86[86];
ovar numeric temp87[87];

define isok(numeric x,numeric y) returning numeric
{
  _caos {
    .inline let $return = TMVT $x(r) $y(r);
  };
}
define walldown() returning numeric
{
  _caos {
     .inline let $return = OBST DOWN;
    };
  };
define wallup() returning numeric
{
  _caos {
     .inline let $return = OBST _UP_;
    };
  };


define deth2(agent a) { agent b,c; b=null();c=heldBy(owner);
				if (c!=b)   { a.tmp=99;}
					else 	{ 
							if (owner.stage_of_life==0) {owner.baseIndex=0;framerate(3); a.anim(4);}
							  if (owner.stage_of_life==1) {owner.baseIndex=0;framerate(3); a.anim(5,4);}
							  if (owner.stage_of_life==9 || owner.stage_of_life==10)  {a.baseIndex=0;framerate(5); 
                                                                                                   a.anim(49,39,29,19,9,8,7,6,5,4);}
							kill(a);
							}	
				}
define deth(agent c) { agent a,b; b=null();//a=heldBy(owner);
				//if (a!=b)   { a.tmp=99;}
					//else {
					 kill(c);
					 //}	
				}
				
define check(agent a) {
 numeric temp=0;numeric temp40;

  if (temp==0) { temp40=0; range (500);
  				_caos{esee 1 4 3002;}; temp40=temp40+1;_caos{next;} 
 	 			if (temp40>7) {kill(a); } temp=temp+1;} //deth2(a) 
 	 			
  if (temp==1) { temp40=0;  
       _caos{etch 1 4 3002;}  temp40=temp40+1;_caos{next;}
       if (temp40>2) {kill(a);} }//deth2(a)  

}		

define grow (agent c) {numeric tmpx,tmpy,t1,t2;agent b;
			tmpx=owner.x();tmpy=owner.y();
			b=newcompound(F_INVISIBLE, G_GOODPLANT, S_ORA,"oraponge", 59 ,0 ,4200);
			b.attributes=192;
			b.perm=100;
			b. elasticity=20;
			b. clickAction=(-1);
			b.acceleration=1;
			b.aerodynamics=5;
			b. friction=100;
			b.pose=4;
			t1=isok(tmpx,tmpy);
			if (t1==1) {b.moveto(tmpx,tmpy);}
		       else  {b.kill;stop(); };
		    
			b.age_of_agent=0;
			b.stage_of_life=0;
			b.bioenergy=50;
			b.tick=5;
			_caos{slow;}
			deth(owner);
}


define seed() { numeric tmpx,tmpy,t1,tt,t3,t4,u;agent b;
				tt=0;t4=0;t3=0;b=owner;
				tmpx=b.x()+2;
				tmpy=b.y()-58;
				t1=70; 	range (500);
				tt=0;
				//this has to be changed !!
				_caos {ESEE 1 4 3003 ADDV $tt(rw) 1 NEXT;}
				if (tt<=4) {t3=getRandom(1,3);}
				if ((tt>=5) && (tt<=7))  {t3=getRandom(1,2);}
				if ((tt>=8) && (tt<=10)) {t3=1;}
				if (tt>10) {t3=0;deth2(b);stop();} //deth2(b)
				if (t3>0) {
		 //reps t3
		 		b=newcompound(F_INVISIBLE, G_GOODPLANT ,S_ORA_SEED, "oraponge", 4 ,0,5000);
				b.attributes=199;
				b.behaviour=32;
			 	b.perm=100;
				b. elasticity=0;
				b. clickAction=(-1);
				b.acceleration=0;
				b.aerodynamics=0;
				b. friction=100;
				t1=isok(tmpx,tmpy);
				if (t1==1) {b.moveto(tmpx,tmpy);}
		       		else  {b.kill;stop(); };
				//tt=getRandom((-1),1);
				b.velocity(tt,-3);
				b.age_of_agent=0;
				b.stage_of_life=0;
				b.bioenergy=20;
				b.tick=1;
				//_caos{slow;}
				}
			   b.stage_of_life=10;
				} 
				
define whatroom(agent a) { 
	if (roomOfTarg(a)==9) { a.temp86=a.temp86+1;
							do {if ((a.temp86>=0) && (a.temp86<=6)) {a.temp87=a.temp87+0.03;}
								if ((a.temp86>6) && (a.temp86<200)) {a.temp87=a.temp87+0.08;}
								a.acceleration=a.temp87;
								} until ((roomOfTarg(a)==9) || (a.temp86 >=200))
							if (a.temp86>200) {wait (getRandom (100,400));deth(a);}
							}
	if (roomOfTarg(a)!=9) { a.temp86=0; a.temp87=0;	}
	a.acceleration=a.temp87;				
}
/*
	subr room
		
		
		doif rtyp room ownr = 9
			setv ov86 0
			setv ov87 0
		endi
		accg ov87
	retn
	*/
define rndm(agent a) { agent b;numeric d;
 do  { a.x_heading=getRandom((-2),2);
 	 } until (a.x_heading!=0);
 d=walldown();
 if (d<500) { do  { a.y_heading=getRandom((-1),1); 	 } until (a.y_heading!=0);}
 if (d>500) { do  { a.y_heading=getRandom((-1),2); 	 } until (a.y_heading!=0);}
 
}	
			
define move_it(agent a) { numeric d,u,l,r;
 u=wallup();d=walldown();l=wallleft();r=wallright();
 if ((d<20) && (u>200)) { a.acceleration=3;a.x_heading=1 ;wait(10);_caos{STOP;};}
 if ((d<20) && (u<=200)) {a.y_heading=(-1);} 
 if (l<50) {a.x_heading=getRandom(2,2);}
 if (r<50) {a.x_heading=getRandom((-2),(-1));}
 if (u<20) {a.y_heading=(2);}
}		


ADDITIONAL OPTIONS

Geany IDE

TODO

  • more commands predefined ...
  • Substituting
script (F_INVISIBLE, G_SYSTEM, S_SIMPLEMONITOR,2000)
with
script (monitor , clicked) ...
  • CAOS code optimization, in the output file

NOTES

Link

Download at http://www.creaturetopia.org/viewtopic.php?f=10&t=117&p=6525#p6525