Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

Description

This object is being used to generate a ‘Loop Counter'. The object is counting from Start to End in certain steps, once triggered. The reset sets the value back to it’s origin. Once the object is trigger it sending out the initial trigger, value and trigger of the current count. Once the executing of all the object path’s behind it are done it will execute again.


App Builder Object


Source Code

function execute() {
  if (context.start === undefined) {
    context.start = parseInt(inPorts[1].value, 10) || 0;
  }
  if (context.end === undefined) {
    context.end = parseInt(inPorts[2].value, 10) || 20;
  }
  if (context.step === undefined) {
    context.step = parseInt(inPorts[3].value, 10) || 1;
  }
  if (context.current === undefined) {
    context.current = context.start;
  }
  switch (trigger) {
    case TRIGGERS.SYSTEM_OUT_DONE:
      if (context.run && context.current < context.end) {
        context.current += context.step;
        sendSync([null, context.current, new Date()]);
      } else {
        context.run = false;
        context.current = context.start;
        unblock();
      }
      break;
    case 0:
      // Trigger
      if (context.run) {
        // Already Running - Start one step before because in loop it will be added again.
        context.current = (context.start - context.step);
      } else {
        context.run = true;
        sendSync([new Date(), context.current, new Date()]);
      }
      break;
    case 1:
      // Start
      if (inPorts[1].value !== undefined) {
        context.start = parseInt(inPorts[1].value, 10);
      }
      break;
    case 2:
      // End
      if (inPorts[2].value !== undefined) {
        context.end = parseInt(inPorts[2].value, 10);
      }
      break;
    case 3:
      // Step
      if (inPorts[3].value !== undefined) {
        context.step = parseInt(inPorts[3].value, 10);
      }
      break;
    case 4:
      context.current = context.start;
      context.run = false;
      unblock();
      break;
    default: break;
  }
}

In Ports

Position

Name

Message Type

Description

1

Trigger

Trigger

This port is being used to start the 'Loop Counter'.

2

Start

Number

This port is being used to define the starting number of the 'Loop Counter'.

3

End

Number

This port is being used to define the end number of the 'Loop Counter'.

4

Step

Number

This port is being used to define the step number of the 'Loop Counter'.

5

Reset

Trigger

This port is being used to reset the executing and reset the counter to the defined start value.


Out Ports

Position

Name

Message Type

Description

1

Initialize Trigger

Trigger

This port is being used to send out the initial trigger once the ‘Loop Counter' object get’s triggered.

2

Value

Number

This port is being used to send out the value of the 'Loop Counter' object.

3

Trigger

Trigger

This port is being used to send out the trigger of the 'Loop Counter' object.


Properties

Name

Description

Object Name

The name of the object on the canvas.

Show Code View

The switch to turn on code view for the Code Object.

Duplicate code into custom Code Object

  • No labels