You are looking at a coding lesson one

This is a basic lesson in coding objects using COWScript

First create a simple object create a fribulator
then code it

Blocks
You can define as many block of code as you like. All of the statements within a block are executed sequentially.
You can jump from one block to another, but remember after jumping to another block, all remaining statements in your first block will be executed after the second block as completed.

A block looks like this:
##{blockname}:

You can call your blocks anything you like but remember these important things:
1) avoid spaces and punctuation in your blocknames
2) keep them all lowercase - I dont know what will happen to you if they are mixed case.
3) make your blocknames unique and logical and avoid trigger words (see reactions below)
this is best done by refering to the actor as 'it' in your block names like 'moveit', 'checkit', 'sayit'


Reactions
The reason you avoid trigger words is that they are used to trigger your object into action. Any trigger word your object hears will cause the block with that same word to execute.

So if you have ##think: or ##get: your object will react if someone thinks or gets something in the same location as it.

NOTE: you can only use the runsub command to name which block you want to peform when the reaction takes place.

See if you can find the trigertrap which shows what triggerwords are heard when actions happen near it.

We now have a more user-friendly way of reacting to triggers that takes for form of 2 IF statements:
if reacting to get the checkgotitem;
if target of get the theygotme;

(I will show the old and new ways in the lessons, but one day the old ways will be forgotten.)

Lets make your object react to somone pushing it.

First make a block that contains the trigger word push

##push:


Now indicate which block of code you would like to run when someone pushes like this:

##push:runsub whattodo;


Now we need to define the whattodo block so it can be executed, like this:

##push:runsub whattodo;
##whattodo:


Now you add as many commands as you like this whattodo block.

Lets make your object jump into the air using the 'say' command like this:

##push:runsub whattodo;
##whattodo:
say 'msg',"[$actor] jumps into the air";


NOTE: the second param of the 'say' command is the string of text everyone gets to see, and it must be in double quotes to work correctly.. due to circumstances beyond our contro you may only see single quotes in the exampels we show here.

Lets see this same code using the new way of reacting:

if reacting to push then whattodo;
##whattodo:
say 'msg',"[$actor] jumps into the air";


Now lets make it do a random thing each time someone pushes it like this:


##push:runsub whattodo;
##whattodo:
var $actn to (jumps,floats,flies,wants to jump,refuses to jump);
say 'msg',"[$actor] $actn into the air";


The variable we create called $actn will contain one of the strings from the list provided. This is a comma seperated list.

We can now use our new variable in the message so your object may 'wants to jump into the air' or 'floats into the air'.

There is essentially no limit to how long the list of choices can be, but if your going to use a long list, I suggest using the load command instead.

Now you object is randomly doing something when it reacts to a push, the next and most crucial thing is to check that your object is the target object of the push! Otherwise your object will react no matter what is pushed, which is probably not what we want.

To achieve this we need to check that the $target object (of the push command) matches the $actor object which is doing the reacting. I will re-arange the blocks slightly and add some space like this:

##push:runsub isitme;

##isitme: if $actor eq $target then whattodo else end;

##whattodo:
var $actn to (jumps,floats,flies,wants to jump,refuses to jump);
say 'msg',"[$actor] $actn into the air";


Notice now that the ##push: is running the isitme block which checks the values and then runs the whattodo block.

if the $actor (your object) is ne (not equal) to the $target (the object that was pushed) the end block is run.

Since we have not defined an ##end: thats ok, nothing will happen.

Since all of the commands in a block will be executed sequentialy, even tho we run another block (iether whattodo or the phantom end) any code after our 'if' statement is executed. Since we have none, no more will happen when a push happens near it.

Lets see this using the new trigger concepts:

if target of push then whattodo;

##whattodo:
var $actn to (jumps,floats,flies,wants to jump,refuses to jump);
say 'msg',"[$actor] $actn into the air";


See how this save the extra step of checking if our $actor is the $target.. this is a good thing as the less lines fo CowScript you have to run, the better.

Finally lets change the colour of your object each time it is pushed.

We could define a variable with a lit of colours like this:
var $clr to (red,blue,ping,green);

but we have the full list of possible colours and a relativly simple way of choosing one randomly like this:


##push:runsub isitme;

##isitme: if $actor eq $target then whattodo else end;

##whattodo:
load colours;
set $actor's colour to "$randomitem";
var $actn to (jumps,floats,flies,wants to jump,refuses to jump);
say 'msg',"[$actor] $actn into the air";


The 2 new lines first read in the entire colour list, then SET a random item from that list into the colour field for the actor (your object)

The anatomy of an object list all of the available propetries (fields) you can set (like changing its location with $actor's loc)

This completes the first lesson of cowscript.