Sets a variable for later use in this instance of cowscript.
It wont be remembered later. If you want to save some information for later use set and write it into an object.
You can use the word 'to' or an equals sign '=' depending on your mood.
Syntax:
var $something to|= {thing};
eg:
var $msg to 'hello there';
var $counter to 5;
var $myhost = $actor's host;
var $random_num to random 10;
var $random_num to random max;
var $tim to today 7 hour format %H:%i on %a;
var $newobj to last obj;
var $state to $target is logged in;
Explanations:
var $msg to 'hello there';
Assigns the string 'hello there' to the variable $msg for later use.
var $counter to 5;
Assigns the number 5 to the variable $counter for later use.
var $myhost = $actor's host;
Reads the value of the actor's host and stores it in the variable called $myhost.
var $random_num to random 10;
Generates a random number between 0 and 10 and stores it in the variable $random_num. You may want to add 1 to $random_num after this if you want a number between 1 and 11;
var $random_num to random max;
Generates a random number from 0 to the ID of the last object created in cow. This is handy for finding a random object in cow out of everything created sofar.
Note: the random number may be one for a deleted object so always check the object eixists - do not assume it exists.
var $tim to today {interval} format {format};
Sets a string into the variable $tim that represents todays date/time modified by the params supplied.
It uses MySQL date/time calculations and formats in one based no todays date/time. So '7 hour' = 7 hours added on to today, and '-4 minute' is 4 munites taken off today. google: [mysql date_add]
The format can be any string using %H = 23 hour time, $i = seconds, $a = the day of the week etc.. google: [mysql format date]
var {$variable} to last obj;
This sets $variable to the obj_id of the last object added to the objects table (last object created). This is useful for finding a random object within the entire object database:
var $tmp to last obj;
var $rnd to random $tmp;
say 'msg',''The last object added was [$tmp] and I randomly choose [$rnd] from all objects'';
var {$variable} to {$object} is log[ged in|on]
Returns a string 'yes' or 'no' indicating that the object/player is logged in right now.
Use this to change how commands work depending on if a player is logged on eg:
var $arethey to $taget is logged on;
if $arethey eq 'yes' then doonething else donothing;
Note: any variation on the phrase 'is log' will suffice so 'is log', 'is logged on' and 'is logorythmically challenged' will all return 'yes' if the object has a current player logged in.
As an added precaution you may want to also check that the object is a player if $target's class eq 'player' ...