*COW* v8.14 on *localhost* - it is 15:24 on Sun papa (you) looks around papa (you) moves close and examines the cask of materials papa (you) starts to read the cask of materials papa (you) looks around papa (you) moves close and examines the coding manual papa (you) moves close and examines the coding manual papa (you) wants to find 'the lessons' and realises there are 7 of them papa (you) wants to find 'the lessons' and realises there are 7 of them papa (you) looks around papa (you) looks around papa (you) wants to find 'the lessons' and realises there are 7 of them papa (you) finds the coding lesson one in the book of coding papa (you) moves close and examines the scripting introduction You examine a scripting introduction (worth 1 pennies) in the library + . Created and owned by wolis at 14:42 on Sun 25 Jun 2006 *Welcome to the wonderful world of CowScript* Scripting allows your objects to react to the world around them. If you find the lessons you will find several lessons covering the basics and some more advanced concepts about scripting. /Please note: scripting is a sub-set of coding, so you can not do everything that is available in coding/ First create an object create a doorbell then script it The first thing you want is to tell your object to react to something. Every message you see has a hidden 'trigger word' and this is what you need to use to get your object reacting. If you read the command called push (or any command for that matter) you should see a section at the bottom describing the trigger keyword and some useful info about this when scripting. The trigger words are generic concepts so both 'get' and 'eat' have the same trigger word of 'get'. A full list of trigger words is available. Send wolis some feedback to find out how. Lets get this doorbell reacting to being pushed.. the trigger word is 'push' so we start scripting like this: | if target of push then someonepushed; ##someonepushed: | The first 'if' statement starts the 'block' of code called 'someonepushed' when it detects a 'push' in the same location as our object and our object is the target. Now we can do something like this: | if target of push then someonepushed; ##someonepushed: print ''[$actor] rings loudly''; | *NOTE: you will have to re-type every double quote (if you cut and paste) as these are 2 single quotes masquarading as double quotes* This means when the doorbell detects a 'push' and its the target then it will print out the message ''the doorbell rings loudly''. You can use these pre-defined variables in your script: *$actor* = the object that is currently performing the script (this is only the initiating player if we are scripting a command) *$target* = the target object when the script was triggered (eg if you push the bell, the bell is the $target) *$second* = the second object referenced when the script was triggered (eg use the key with the door. $target=key, $second = door) *$init_obj* = the object that caused the script to start (usually this is the player who typed the 'push' or 'use' commands etc..) *$loc* = the location where the script was triggered Now lets be a bit more creative with the response by making some variables random containing random text: | if target of push then someonepushed; ##someonepushed: $sound = (rings,dings,bings,doings,goes ka-thump); $vol = (softly,loudly,slowly,quickly); print ''[$actor] $sound $vol''; | Now we are defining 2 variables *$sound* and *$vol* and we are assigning a random string of text from the lists in brackets to each. Variables always start with a dollar sign *$* and contain a string of letters and possibly numbers, no punctuation. Keep it as short, unique and simple as possible and void key variables like $target and $actor and $action etc..(this will just break your script). So now your will get ''the doorbell dings quietly'' or ''the doorbell goes ka-thump quickly''. An object can react to many different trigger words and contain many different blocks of code. Lets add a few more blocks of code and make the doorbell react to 'use' when someone uses it. Again we will need to check that we are the object being used. | if target of push then someonepushed; if target of use then someoneused; ##someonepushed: $sound = (rings,dings,bings,doings,goes ka-thump); $vol = (softly,loudly,slowly,quickly); print ''[$actor] $sound $vol''; ##someoneused: runsub someonepushed or makeamove or donothing; ##donothing: print ''[$actor] does not seem to respond''; ##makeamove: $dir = (up,down,left,right,backwards,forwards); $actn = (dodges,slides,wriggles,bounces,looks,winks,gestures); $look = (blinks,looks,winks,glares,ignores); print ''[$actor] $look at [$init_obj] then $actn $dir''; runsub someonepushed/3; | Now we have a rather complex object. When used, it radomly runs one of three blocks of code. The *donothing* block is rather boring and just prints out a single message. The *makeamove* is simlar to *someonepushed* as variables are defined and combined in the print, which this time makes reference to the player who used it. The final line of this block will have a one in 3 chance of running the *someonepushed* after it has finished.. This is what the /3 means. We could have the *someoneused* block do this: | ##someoneused: runsub someonepushed/2 or makeamove/4 or donothing; | In which case we have a one in three chance of doing each of the three blocks. However when trying to run the first 2, there is a one in 2 and one in 4 chance respectively, of actually doing it. This will result in alot of nothing happening.. which sometimes you may want. (note: thanks intercal for this concept - as well as the 'please' and 'thankyou' which COWScript supports) Finally, lets add a bit of code to this object so that it does something when someone arrives by adding this code: | if reacting to arrives then greetthem; ##greetthem: $actn = (blinks,stops what it was doing,quickly stops laughing,jumps); print ''[$actor] $actn because [$init_obj] arrives''; | Since the doorbell is not the target when someone arrives, we simply want to react to a keyword so we use |if recting to ...| This new reaction and block of code can go anywhere in the existing script.. however its good practice keeping all of your reactions at the top of your script so you can quickly see what your object reacts to. ------------------------------------------------------------------------ Old stuff about but still useful for other occasions.. The first thing you will notice about this doorbell is that it will ring as soon as it detects a 'push' even if its not the doorbell being pushed, so lets add a little bit of logic to our script to make sure it only reacts if it is pushed: | if reacting to push then someonepushed; ##someonepushed: if $actor = $target then makeasnd; ##makeasnd: print ''[$actor] rings loudly''; | Now we have 2 blocks of code. The new one called *makeasound* will only be executed if the $actor equals the $target. Cow is very forgiving and will allow several varieties of equals depending on which scriping language you are more familiar with eg: | $actor eq $target $actor equals $target $actor = $target $actor == $target | Execution stops at the end of a block (when a new one starts) however you can run bocks of code (with 'runsub' or 'goto') from within the current block of code. read the info on store This is 6 years, 20 days and 42 minutes old 100% healthy xxxxxxxxxx (10/10) look around , write in it , describe it , paint it , push it , get it , put it on something , or check out other commands email this Cmd: Say: ! currently logged in nudge the scripting introduction up , down , left , right , paint it , edit it , push it exam <#> find <#> find <#> exam <#> exam <#> exam <#> exam <#> read <#> exam <#> look <#> read <#> read about examine