Browse Source

Add Input function

This function takes a value from an external source and pushes it onto
the runtimeInput array. If the computer is on but awaiting input, its
Run function is called to start it again.
ApisNecros 1 year ago
parent
commit
5427eacf12
1 changed files with 14 additions and 0 deletions
  1. 14 0
      IntComp/Computer.js

+ 14 - 0
IntComp/Computer.js

@@ -484,6 +484,20 @@ module.exports = class Computer {
         return this.HasOutput() ? this.outputValues.shift() : undefined;
     }
 
+    /**
+     * Accept input from an external source
+     *
+     * The input given here is pushed onto the end of the computer's runtime
+     * input array.
+     *
+     * @param {number} inputValue The number to push onto the runtime input array
+     * @returns {void}
+     */
+    Input(inputValue) {
+        this.runtimeInput.push(inputValue);
+        if (this.running && this.awaitingInput) { this.Run(); }
+    }
+
     /**
      * Resets the computer's memory to the value it was created with
      *