User Tools

Site Tools


chataigne

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
chataigne [2023/02/17 14:23] ssm2017chataigne [2023/02/17 17:54] (current) – [Values in script] ssm2017
Line 18: Line 18:
 <sxh js> <sxh js>
 var mycontainer = local.values.addContainer("toto"); var mycontainer = local.values.addContainer("toto");
-var myint1 = mycontainer.addIntParameter("myint", "",0,1,65536);+var myint1 = mycontainer.addIntParameter("myint", "",1,1,65536);
 myint1.setAttribute("saveValueOnly",false); myint1.setAttribute("saveValueOnly",false);
 +</sxh>
 +===== Custom variables =====
 +<sxh js>
 +function getCustomVariablesGroup(name, shortname) {
 +  var my_group = root.customVariables.getItemWithName(shortname);
 +  if (my_group.name != shortname) {
 +    // build a new group
 +    my_group = root.customVariables.addItem(shortname);
 +    my_group.setName(name);
 +  }
 +  return my_group;
 +}
 +
 +/**
 + * Set or create then set the custom variable value
 + * @param {int} page_id 
 + * @param {int} exec_id 
 + * @param {int} value 
 + * @param {string} type 
 + * @param {string} item_nice_name 
 + */
 +function setCustomVariablesValue(page_id, exec_id, value, type, item_nice_name) {
 +  // build names
 +  var shortname = "exec"+ page_id+ "_"+ exec_id;
 +  var name = "Exec "+ page_id+ "_"+ exec_id;
 +  // get the group
 +  var my_group = getCustomVariablesGroup(name, shortname);
 +  // define the item type
 +  var item_name = type;
 +  var item_type = "Int";
 +  var int_max = 100;
 +
 +  if (["Go", "Stop", "Resume", "Off"].contains(type)) {
 +    item_type = "Bool";
 +  }
 +  // build some names
 +  var my_value = {};
 +  var my_value_name = "exec"+ page_id+ "_"+exec_id+ item_name;
 +  var my_value_nice_name = "Exec "+ page_id+ "_"+ exec_id+ " "+ item_nice_name;
 +
 +  var my_value_item = my_group.variables.getItemWithName(my_value_name);
 +  if (my_value_item.name != my_value_name) {
 +    // create if not exist
 +    my_value_item = my_group.variables.addItem(item_type+ " Parameter");
 +    my_value = my_value_item.getChild(my_value_item.name);
 +    my_value.setName(my_value_nice_name);
 +
 +    if (["CueMsb", "CueLsb"].contains(type)) {
 +      int_max = 999;
 +    }
 +    if (["Hour", "Minute", "second"].contains(type)) {
 +      int_max = 60;
 +    }
 +    if (!["Go", "Stop", "Resume", "Off"].contains(type)) {
 +      my_value.setRange(0,int_max);
 +    }
 +  }
 +  else {
 +    my_value = my_value_item.getChild(my_value_item.name);
 +  }
 +  if (["Go", "Stop", "Resume", "Off"].contains(type)) {
 +    my_value.set(true);
 +    my_value.set(false);
 +  }
 +  else {
 +    my_value.set(value);
 +  }
 +  my_group.variables.reorderItems();
 +}
 </sxh> </sxh>
chataigne.1676640212.txt.gz · Last modified: by ssm2017