mayacakmak / emarsoftware

Front end tools for designing robot faces, setting up custom robot APIs, and controlling a robot (WoZ)
BSD 2-Clause "Simplified" License
2 stars 12 forks source link

Inability to create functions #86

Open pianokitkat opened 2 years ago

pianokitkat commented 2 years ago

Currently we cannot make functions in the software. Can we enable the creation of functions? (Or call other programs from one program). This is for the idea of randomly selecting from a variety of functions that each go through a different short interaction.

mayacakmak commented 2 years ago

The code written in the 'EMAR robot programming' tools is essentially Javascript and should allow everything you can do in Javascript, including loops, randomization, and defining/calling functions. Below is a simple example that I just tested and seems to work.

var greetings = ["hello", "hi", "greetings"];
var buttonName = null;
for (let i=0; i<greetings.length; i++) {
  let rand = getRandomInt(greetings.length);
  console.log(">>>>>>> " + i);
  console.log("rand " + rand);
  robot.setScreen(i);
  robot.speak(greetings[rand]);
  await robot.sleep(2000);
}

function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}
mayacakmak commented 2 years ago

Also see program Fixed_Interaction_2_10 on "Test Robot" for dealing with having asynchronous calls within a function that you define (mainly you need to define the function to be async).