Browse Source

Add HasOutput function

ApisNecros 1 year ago
parent
commit
910d63d12e
1 changed files with 11 additions and 2 deletions
  1. 11 2
      IntComp/Computer.js

+ 11 - 2
IntComp/Computer.js

@@ -466,13 +466,22 @@ module.exports = class Computer {
         console.log(outputMessage, util.inspect(toInspect, { breakLength: Infinity, colors: true, compact: true }));
     }
 
+    /**
+     * Check if the computer has any values in the output array
+     *
+     * @returns {boolean} True or false if there are any values in the output array
+     */
+    HasOutput() {
+        return !!this.outputValues.length;
+    }
+
     /**
      * Get a value from the unhandled OUTPUT values in FIFO order
      *
-     * @returns {number} An unhandled value from an output call
+     * @returns {number|undefined} An unhandled value from an output call, or undefined if the array is empty
      */
     FetchOutputValue() {
-        return this.outputValues.shift();
+        return this.HasOutput() ? this.outputValues.shift() : undefined;
     }
 
     /**