Node Script

Number Array To Console

Downloads: 13
Download
Ads Support FTD

Description

Outputs a Number Array to the console

//
// --------------------------------------------------------
// NumberArrayToConsole
// Outputs a Number Array to the console
// Written by @Fusedthreed – https://FusedThreeD.com
// --------------------------------------------------------
//

@customNode()
export class LogNumberArray extends BasicScriptNode {

  @input()
  Number_Array: number[];

  // Name/label shown in console
  @input()
  Array_Name: string = "Array";
  @input()
  Log_On: boolean = true;
  // true = one line, false = separate lines
  @input()
  One_Line: boolean = false;

  // true = pretty print, false = normal print
  @input()
  Pretty_Print: boolean = true;

  execute() {
    if(this.Log_On === false){
      return;
    }
    if (!this.Number_Array || this.Number_Array.length === 0) {
      if (this.Pretty_Print) {
        console.log(`┌─ ${this.Array_Name}`);
        console.log(` (empty or undefined)`);
        console.log(`└────────────`);
      } else {
        console.log(`${this.Array_Name}: array is empty or undefined`);
      }
      return;
    }

    // ONE LINE
    if (this.One_Line) {

      if (this.Pretty_Print) {
        console.log(`┌─START ${this.Array_Name}[${this.Number_Array.length}]`);
        console.log(`${this.Number_Array.join(", ")}`);
        console.log(`└─END ${this.Array_Name}`);
      } else {
        console.log(`${this.Array_Name}: ${this.Number_Array.join(", ")}`);
      }

      return;
    }

    // MULTI LINE
    if (this.Pretty_Print) {
      console.log(`┌─START ${this.Array_Name}[${this.Number_Array.length}]`);
      let o = "";
      for (let i = 0; i < this.Number_Array.length; i++) {
        console.log(`[${i}] [${i}] ${this.Number_Array[i]}`);
      }
      console.log(`└─END ${this.Array_Name}`);
    } else {
      console.log(`${this.Array_Name}:`);
      for (let i = 0; i < this.Number_Array.length; i++) {
        console.log(`  [${i}] ${this.Number_Array[i]}`);
      }
    }
  }
}
Ads Support FTD