Cycling through custom areas

Here's an improved, generalized version of this:

async function cycleThrough(triggers) {
  let cycleName = "cycle-" + triggers.join('-'); // Build a unique counter name
  let counterValue = await callBTT('get_number_variable', {variable_name: cycleName});

  // Initialize the value in BTT
  if(counterValue === undefined) {
	await callBTT('set_number_variable', {variable_name: cycleName, to: 0});
	counterValue = 0;
  }
    
  // Cycle through them
  let modCounter = counterValue % triggers.length;	
  callBTT('trigger_named_async_without_response', {trigger_name: triggers[modCounter]});
  
  // Increment the counter
  await callBTT('set_number_variable', {variable_name: cycleName, to: modCounter+1});

  // return to BTT
  returnToBTT(counterValue);

}

// Cycle through the given triggers
cycleThrough([
  "leftHalf",
  "leftTwoThirds",
  "leftOneThird"
]);

(You still have to create the referenced Reusable Named Triggers.)

@Andreas_Hegenberg: Is there some global place that helpers, like the cycleThrough could be added so that the trigger just becomes the usage of that method?

2 Likes