Here is a simple UI Action that allows you to create a recipe through JavaScript code - you can of course also use the code inside a LocalScript. Please note the parameters defined when creating this UI Action, otherwise it won't work: /**
* Custom UI-Action 'create-recipe'.
*
* Description:
* [Add description here]
*/
(function() {
var actions = shmi.pkg("visuals.session.userActions"); //get reference to userActions object
/**
* UI-Action 'create-recipe' implementation
*
* @params {any[]} parameters configured ui-action parameters
* ---- Initial parameters, needs to be updated manually when changed ----
* @param {number} parameters[0] Recipe Template ID
* @param {string} parameters[1] Recipe Name Prefix
*
*/
actions["create-recipe"] = function(parameters) {
// Place your code here
const templateId = parseInt(parameters[0]),
recipeName = parameters[1] + Math.random(),
rm = shmi.requires("visuals.session.RecipeManager");
rm.getTemplate(templateId, function(response, err) {
if (err) {
shmi.notify("Could not fetch recipe template: " + err.message, "${V_ERROR}");
} else {
console.log('Creating recipe...');
console.log(response);
response.createRecipe(recipeName, {}, function(newRecipe, createErr) {
if (createErr) {
shmi.notify("Could not create recipe: " + createErr.message, "${V_ERROR}");
} else {
console.log("Created recipe!");
console.log(newRecipe);
shmi.notify(`Recipe created: '${newRecipe.name}.' with ID #${newRecipe.id}`, "${V_ERROR}");
}
});
}
});
};
}());
... View more