Robot competencies, which are in general different robot behaviors, which engage one or more of his modules are best example of more complex urbiscript code. The following listings are taken from ready-made Emys competency files, which can be found in urbiscipts/competencyManager.

dialogue

Dialog competencies allowed easy extension of number of languages which robot speaks, number of available speech sequences which robot uses and randomization of robot utterances. The following examples comes from EmysDialogs.u and SpeechSequences.u.

if (!robot.hasLocalSlot("dialogue")) robot.addComponent("dialogue");//we add dialogue component to robot structure
//we create table of speech sequences and fill it with phrase empty in three different languages (English, Polish and Portuguese)
var robot.dialogue.speech_sequences = [[" empty "," pusty "," vazio "]];
for&(var i:1000) {robot.dialogue.speech_sequences << [" empty "," pusty "," vazio "];};
//we define robot speech sequences in all supported languages
var _lang_tmp;
_lang_tmp = 0;//English  
robot.dialogue.speech_sequences[80][_lang_tmp] = "Monday";
robot.dialogue.speech_sequences[81][_lang_tmp] = "Tuesday";
robot.dialogue.speech_sequences[82][_lang_tmp] = "Wednesday";
robot.dialogue.speech_sequences[83][_lang_tmp] = "Thursday";
robot.dialogue.speech_sequences[84][_lang_tmp] = "Friday";
robot.dialogue.speech_sequences[85][_lang_tmp] = "Saturday";
robot.dialogue.speech_sequences[86][_lang_tmp] = "Sunday";
_lang_tmp = 1//Polish
robot.dialogue.speech_sequences[80][_lang_tmp] = "poniedzia\xc5\x82ek";
robot.dialogue.speech_sequences[81][_lang_tmp] = "wtorek";
robot.dialogue.speech_sequences[82][_lang_tmp] = "\xc5\x9broda";
robot.dialogue.speech_sequences[83][_lang_tmp] = "czwartek";
robot.dialogue.speech_sequences[84][_lang_tmp] = "pi\xc4\x85tek";
robot.dialogue.speech_sequences[85][_lang_tmp] = "sobota";
robot.dialogue.speech_sequences[86][_lang_tmp] = "niedziela";
_lang_tmp = 2//Portuguese
robot.dialogue.speech_sequences[80][_lang_tmp] = "segunda-feira";
robot.dialogue.speech_sequences[81][_lang_tmp] = "ter\xc3\xa7a-feira";
robot.dialogue.speech_sequences[82][_lang_tmp] = "quarta-feira";
robot.dialogue.speech_sequences[83][_lang_tmp] = "quinta-feira";
robot.dialogue.speech_sequences[84][_lang_tmp] = "sexta-feira";
robot.dialogue.speech_sequences[85][_lang_tmp] = "s\xc3\xa1bado";
robot.dialogue.speech_sequences[86][_lang_tmp] = "Domingo";
//now we can simply set current language:
var robot.dialogue.language = 0;
//and say different phrases calling robot.dialogue.Say function
robot.dialogue.Say(robot.dialogue.speech_sequences[30][robot.dialogue.language],false);      
//robot.dialogue.Say function can automatically detect that given phrase is in English and reflect the robot emotional state in the moving speed 
function d_Say(text, check_lang)
{
var isEnglish = false;
//if current language is different than English and check_lang parameter is true, check if given text is English one
if ((check_lang)&&(robot.dialogue.language!=0)) isEnglish = robot.dialogue.CheckIfEnglish(text);
//remove tags from text
text = text.replace("<","").replace(">","");
text = text + "\0";
//if emotion component is active, read the movingSpeed parameter, which will affect the moving speed 
var _s_emot = 0;
if (robot.hasLocalSlot("emotion")) _s_emot = robot.emotion.movingSpeed/4;
//if English was detected, speech synthesis will switch to English voice, if not speech synthesis voice will be chosen by robot.dialogue.language
if (isEnglish) 
robot.body.neck.head.Say(text,5+_s_emot,0)
else
robot.body.neck.head.Say(text,5+_s_emot,robot.dialogue.language);
};
//automatic English detection is very useful when robot is speaking in some different language and occasionally it has to read something in English (e.g. news from foreign website or e-mail). Robot will then automatically switch to English voice synthesis.
//aggregation of speech sequences in vector has two additional benefits:
//first one is easy randomization of speech sequences, e.g.
function d_SayNoEmails()
{
robot.dialogue.Say(robot.dialogue.speech_sequences[273+3.random][robot.dialogue.language],false);
};  
//the above function will say one of three different sequences - 273, 274 or 275. They all mean the same, but content is said in different words so robot seems to less repeatable
robot.dialogue.speech_sequences[273][_lang_tmp] = "You have no new messages.";
robot.dialogue.speech_sequences[274][_lang_tmp] = "There are no new messages.";
robot.dialogue.speech_sequences[275][_lang_tmp] = "No new messages.";
//the second is easy way to say some number related utterances (e.g. weather forecast which is downloaded as a code)
//a piece of d_SayWeather function:
// The temperature outside is... and the weather is...
var tmp = robot.dialogue.speech_sequences[90][robot.dialogue.language] + " "+ _temperature.asString + " "+ robot.dialogue.speech_sequences[91][robot.dialogue.language] + " "+ robot.dialogue.speech_sequences[100+_code][robot.dialogue.language] +".";
robot.dialogue.Say(tmp,false);
//100+_code allows robot to simply say (function code is very neat) about weather conditions:
robot.dialogue.speech_sequences[100][_lang_tmp] = "tornado";
robot.dialogue.speech_sequences[101][_lang_tmp] = "tropical storm";
robot.dialogue.speech_sequences[102][_lang_tmp] = "hurricane";
robot.dialogue.speech_sequences[103][_lang_tmp] = "severe thunderstorms";
robot.dialogue.speech_sequences[104][_lang_tmp] = "thunderstorms";
robot.dialogue.speech_sequences[105][_lang_tmp] = "mixed rain and snow";
robot.dialogue.speech_sequences[106][_lang_tmp] = "mixed rain and sleet";
robot.dialogue.speech_sequences[107][_lang_tmp] = "mixed snow and sleet";
robot.dialogue.speech_sequences[108][_lang_tmp] = "freezing drizzle";
robot.dialogue.speech_sequences[109][_lang_tmp] = "drizzle";
robot.dialogue.speech_sequences[110][_lang_tmp] = "freezing rain";
//and so on ...  

 

 

EMYS and FLASH are Open Source and distributed according to the GPL v2.0 © Rev. 0.9.1, 15.05.2017

FLASH Documentation