Allow named object variables and allow actions with multiple variables to be saved as object properties
I often wish I could create objects instead of grouping variables by naming convention. It can get messy if you have 2 or more of the same types of objects to track. If named objects could be implemented, it would be possible to store multiple values to a single variable name and constrain usable properties to the object's structure. The structure would help 'group' properties for variables of a similar type.
In terms of integration, it would be great to have the option and flexibility with actions that output multiple variables. A good use case is creating a profile for "App changed". When the event fires, it creates variables %app_icon, %app_name, and %app_package. If my task has an action of "App Info", it returns using the same variable names. If I am using these variables to compare the two, I would have to store the %app_name of the event to a different variable before I call App Info.
For example, if I call App Info as the first action in my task, it will overwrite the variables from the event (or Profile) if I do nothing. In a new text box, I could assign the output of App Info to a variable name and access the individual variables as properties using dot notation. This would look similar to %myVar.app_name. Below is some pseudo-JS for better context.
/* In this use case, I would expect a specific app to fire the
* event. The task would perform a check to verify the app is
* still open. When the original app opens a different app, it
* would perform a check while the different app is open. If
* I switch back to the first app, I want to continue checking.
*/
var myVar = new App_Info();
myVar.Label = "myGotoLoop";
// app_name would belong to the event, but I can use dot
// notation if I declare a variable for new App_Info() to
// stuff its output into.
if(app_name ~ myVar.app_name)
{
//Perform check while I still have the app open.
Wait(1000); // ms, meaning 1 second.
Goto("myGotoLoop");
}
// The app that fired the event lost focus
var myOtherVar = new App_Info();
myOtherVar.Label = "myOtherGotoLoop";
if(app_name ~ myOtherVar.app_name)
{
//Perform a different check while I have a different app open.
Wait(1000); // ms, meaning 1 second.
Goto("myOtherGotoLoop");
}
// The 'different' app lost focus. Restart checks on the app
// that fired the event.
if(app_name ~ myVar.app_name)
{
Goto("myGotoLoop");
}
exit();
In a scenario where an action is not involved:
// Tasker would require pre-defining the object structure
var booksObject = {
title: undefined, //type: string
desc: undefined, //type: string
price: undefined, //type: int
upc: undefined //type: string
};
// Then, using the "Variable Set" action, it would clone the object to
// reuse and constrain the structure
var book1 = Object.clone(booksObject);
var book2 = Object.clone(booksObject);
var book3 = Object.clone(booksObject);
book1.title = "The first book title"
book1.desc = "A brief description about this book.";
book1.price = 10.95;
book1.upc = "01234567890";
book2.title = "The second book title"
book2.desc = "A brief description about this book different from the first.";
book2.price = 14.95;
book2.upc = "09876543210";
book3.title = "The second book title"
book3.desc = "A brief description about this book different from the first.";
book3.price = 19.95;
book3.upc = "05678912340";
var priceTotal = book1.price + book2.price + book3.price;
//result: 45.85
// Because UPC is typeof string, it would concatenate instead of add.
var upcTotal = book1.upc + book2.upc + book3.upc;
// result: "012345678900987654321009876543210"
// If I wanted to display a book in a notification, it would convert the
// object to a readable format.
// Assuming displayNotification's constructor is
// displayNotification(title, message)
displayNotification("Book 1", book1);
//result:
┌---------------------------------------┐
| Book1 |
└ - - - - - - - - - - - - - - - - - - - ┘
| title: The first book title |
| desc: A brief description about this |
| book. |
| price: 10.95 |
| upc: 01234567890 |
└---------------------------------------┘