Getting a SILVIA Variable to Drive Behavior
The SILVIA brain can also be used to retrieve a variable to be processed for driving behaviors or actions in Unity. For example you have a command and control dashboard where the driver recites their PIN when SILVIA queries them to access their particular stored preferences. SILVIA now knows the driver’s name is Bob, the geocoordinates of his home and office and favorite stores and restaurants. You have set up a DashboardController component that acts as a master interface between SILVIA and all the rest of the components making up the dashboard. In that script you have references to each of the various components and methods for SILVIA to interface with them.
To access the methods of this component, declare a public reference in a Behavior labeled group “default” and name “boot”, in the Pre- or Post-Exuder Section of the Behavior Scripts.
public DashboardController dashboardCtrl;
This will be the gateway to accessing the other components who have references within this component. In this example let’s define a component that stores and retrieves the drivers preferences within the DashboardController component.
public DriverPreferences driverPrefs;
In the DriverPreferences you would set a reference to store the current driver home geocoords a a Vector2 for ease of compactness.
public Vector 2 driverHomeGeocoords;
To begin with let’s use SILVIA and the PIN to access the drivers name. SILVIA would call this method from the DashboardController reference using the following pattern.
public bool Invoke() {
//SILVIA call to method below
string driverName = dashboardCtrl.driverPrefs.GetDriverName(PIN);
//here set the variable for SILVIA core
}
Which would return the string “Bob” from the stored preferences based on the key PIN string.
public string GetDriverName (int PIN) {
string key = driver + PIN.ToString() + name; string driverName = “”;
if (PlayerPrefs.HasKey(key) {
driverName = PlayerPrefs.GetString(key);
}
return driverName;
}
In this example the driverName returned is “Bob”. SILVIA can now reference all the variables under the Bob group and name. Previously the geocoords for his home and office were recorded by SILVIA and loaded at boot along with other drivers, if any, preferences. They can be retrieved using the GetVariable method of SILVIA.
public bool Invoke () {
//GetVariable of driverHomeGeocoords from SILVIA
//For example ”$origin” in SILVIA Core is “31.0067,-84.8005” Vector2 geocoords = new Vector2();
string[] coordsSplit = Core.GetVariable(“$origin”).Split(“,”); geocoords.x = float.Parse(coordsSplit[0]);
geocoords.y = float.Parse(coordsSplit[1]);
//set the variable on the driverPrefs component dashboardCtrl.driverPrefs.driverHomeGeocoords = geocoords; return true;
}
Since SILVIA stores Core Variables as strings by default, it is necessary to parse the data of “$origin” back into the desired format or type. In this case, splitting the latitude and longitude in “$origin” by the comma leaves you with two strings you can Parse as float values to put into the Vector2 that holds the geocoords.
Making a new blank Vector2 beforehand creates a container for those values to be passed into.
The drivers home geocoordinates are now available in the components to be accessed for GPS locator services and mapping applications such as getting routes from origin to destination. Using the few techniques for getting and setting SILVIA Core variables outlined above very complex voice driven command and control scenarios can be architectured from a few basic patterns and a master component controller SILVIA references to access all the other controllable components parameters, variables, properties and methods.