CowScript - wolispace/creativeobjectworld GitHub Wiki
CowScript is a set of command (cowmand) statements performed in sequence and grouped into blocks.
A block of cowmands starts with a double has '##' and ends at the first space. (previously this was a colon - one less character is a good thing).
A cowmand statement consists of a cowmand name and a string of parameters.
Its up to each individual cowmand to parse the params - eg: the cowmand 'say' will use all parameters as one string, while the cowmand 'if' will need to do some regex like /^if\s(.+)\s(equals|is|like|in|eq|ne|>|<|!=|>=|<=|=|==) (.+) then (.+)/i
There is a fixed number of cowmands that can be used in cow script that handle user input and modify the database accordingly. These are hard-coded into the processor.js. However the cowmand "call" simulates user input.. so cowScript can perform any command a user could.
When a user types in a command eg: "push the baby elephant" we first find an object that holds the cowScript with a name
of "push"
This object can be global - it can exist anywhere and be of class "command". Or the can be local - it can have any class but must be in the current actor's location. Or the can be private - they can have any name but reside within the actor.
Finding objects to perform is done in reverse order.. in the actor, the location the global.
Custom dictates local and private command objects are classed as action
so they are easy to find, however hiding a local command is also a common practice to override the default (blobal)
When we find a suitable object named "push" we process its cowScript.
Here is a sample cowScript for push (from the old cow so may not match the new syntax)
get $target in $loc; if $target > 0 then unhostit else fail; ##unhostit: clear $target,all; say 'push',"[$actor] pushes [$target]"; relook $loc; rem look $loc; rem msg $loc,$actor,0,0,'force',"force:look $loc";
runsub noisy/3; ##noisy: msg 0,$actor,0,0,"act","You hear a gentle thud"; ##fail: var $click_cmd to 'push'; var $desc_intro to 'Click on the object you want to push:
'; look $loc,list; msg $loc,$actor,$actor,0,'force',"force:look $loc,list";
Curse this markdown editor!
A list of cowmands from the old cow..
- add
- call (with time delay)
- call
- clear
- code
- dedupe
- copy
- divide
- find
- foreach
- fixplural
- get
- getname
- goto
- if
- load
- loop
- mode
- motion
- msg
- multiply
- new
- nudge
- percentbar
- refresh
- goto/runsub???
- save
- say
- set
- swap
- take
- var
These are in the code but not documented so are later additions or I forgot to document them:
- case
- combine
- cycle
- delete
- export
- get
- getgender
- implode list
- include
- incr
- locate
- modify value at..
- multiset
- multivar
- parseObj
- position of..
- relist
- relocate
- relook
- rem
- sayto
- store
- switch
- touch
- unhost
- update
- value at..
- value for/manipulate
- variation on var..
msg is the cornerstone of cow. everything that perceivably takes place is broardcast via a msg.
messages are add to the "messages" in the database
messages has a trigger word assigned to them, so anything that want's to react simply looks for a matching trigger word. eg: if you say someone picked up something, the trigger word would be 'get'. so if an object wants to react to being picked up, it checks for 'get' and if its the target of 'get' it can do something about it.