From fdd58af63ecc2882c0e002874f56909abada4215 Mon Sep 17 00:00:00 2001 From: Raktbastr Date: Sun, 6 Apr 2025 09:28:09 -0500 Subject: [PATCH] Fixed sleep function issue and writing to global variables. --- files/functions.js | 13 +++++++++---- files/main.js | 9 +++++---- files/poiscreens.js | 6 +++--- files/variables.js | 40 ++++++++++++++++++++-------------------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/files/functions.js b/files/functions.js index e7632f9..70fd95c 100644 --- a/files/functions.js +++ b/files/functions.js @@ -3,8 +3,10 @@ import { createRequire } from 'module'; const require = createRequire(import.meta.url); var readlineSync = require('readline-sync'); const { exec } = require("child_process"); +import { promisify } from "util"; +const execPromise = promisify(exec); + -import { food, foodRate, health, healthCap, locationA, locationB, name, radPoints, radSeverity, walkRate } from "./variables.js"; // Used for basic functions, not game specific export function userInput(question) { // Basic user input functions, takes in the question to be asked. @@ -82,9 +84,12 @@ export function calcLocation() { } } - -export function sleep(time) { - exec("sleep "+time); +export async function sleep(time) { + try { + await execPromise(`sleep ${time}`); + } catch (error) { + console.error("Error executing sleep command:", error); + } } function death() { diff --git a/files/main.js b/files/main.js index 0602886..fd53310 100644 --- a/files/main.js +++ b/files/main.js @@ -21,9 +21,9 @@ console.log("--------------------------"); console.log("1) Start new game"); console.log("2) Learn How to play"); console.log("3) Quit Game"); -console.log("4) Dev stuff for testing"); +console.log("4) Dev stuff for testing\n"); -var mainMenuInput = userInput("Enter: ") +var mainMenuInput = userInput("Enter: "); switch(mainMenuInput) { case "1": @@ -35,6 +35,7 @@ switch(mainMenuInput) { break; case "3": console.log("Quitting Game..."); + await sleep(1); break; case "4": for(var a = 0; a < 10; a++){ @@ -50,14 +51,14 @@ switch(mainMenuInput) { function startGame() { // So far what I have is filler and testing, feel free to change. console.clear(); - variableChange("name","=",userInput("What is your name? ")); + name = userInput("What is your name? "); console.log(name+" Is now your name...") console.clear(); console.log("Intro:"); console.log("You are an ordinary loyal Enclave Soldier working at Raven Rock. \nYou are typing away at your terminal, entering reports of recovered materials when a message flashes on it"); console.log("|||||||") console.log("|| Enclave Intranet Messager"); - console.log("") + console.log("|||||||") console.log("|| Message From: potus"); console.log("|||||||\n\n") console.log("Dear "+name+",\n\n This is a direct order from the Enclave High Command. \nIgnore all previous directives. Proceed to Camp Navarro immediately. \nSeek safe passage through the Brotherhood and NCR territories. \nDo not disclose your mission to anyone but Enclave Personel with \nsecurity clearance 5 or higher. Reqisition supplies before departure. \nYou have been given 1 YEAR to complete this mission or face discharge.\n\n Signed, President John Henry Eden\n\n"); diff --git a/files/poiscreens.js b/files/poiscreens.js index 6ebbd87..474cf45 100644 --- a/files/poiscreens.js +++ b/files/poiscreens.js @@ -1,7 +1,7 @@ // Holds poi code, seperate from encounters.js import { userInput } from "./functions.js"; -import { location, locationA, locationB, path } from "./variables.js"; +import './variables.js'; export function checkPOI() { if (path == 0) { @@ -91,8 +91,8 @@ export function checkPOI() { } } -export var poiCounter = 0; -export var pois = [ +global.poiCounter = 0; +global.pois = [ {name: "Whitespring Bunker", location: 25, path: 0, visited: false}, {name: "BOS Bunker Gamma", location: 100, path: 0, visited: false}, {name: "BOS Bunker Delta", location: 125, path: 0, visited: false}, diff --git a/files/variables.js b/files/variables.js index e709fbe..a439559 100644 --- a/files/variables.js +++ b/files/variables.js @@ -1,19 +1,19 @@ // Now holds only variables // Player Currency -export var prewarmoney = 0; // Used with enclave vendors -export var caps = 0; // Used with all other vendors +global.prewarmoney = 0; // Used with enclave vendors +global.caps = 0; // Used with all other vendors // Player Stats -export var healthCap = 0; // Maximum health, raises each level -export var health = 0; // Players current HP -export var food = 0; // Amount of food player has -export var isRadiated = false; -export var radSeverity = 0; // Modifies healthCapCalc. 3 Levels -export var radPoints = 0; // If the player reaches 100 rad points the game ends -export var xpPerLevel = 10; // Amount of XP needed per level. Raises 50% each level -export var level = 0; // Level of player. Modifies enemy scaling -export var inventory = [ // Inventory of player, holds all items +global.healthCap = 0; // Maximum health, raises each level +global.health = 0; // Players current HP +global.food = 0; // Amount of food player has +global.isRadiated = false; +global.radSeverity = 0; // Modifies healthCapCalc. 3 Levels +global.radPoints = 0; // If the player reaches 100 rad points the game ends +global.xpPerLevel = 10; // Amount of XP needed per level. Raises 50% each level +global.level = 0; // Level of player. Modifies enemy scaling +global.inventory = [ // Inventory of player, holds all items // Supplies: chems, aid [], // Equipment: weapons, armor, tools @@ -21,20 +21,20 @@ export var inventory = [ // Inventory of player, holds all items ] // Game Mechanics -export var walkRate = 0; // Units the player walks per day, affects foodRateCalc and radPointsCalc -export var foodRate = 0; // Amount of food player eats per day, affects radPointsCalc +global.walkRate = 0; // Units the player walks per day, affects foodRateCalc and radPointsCalc +global.foodRate = 0; // Amount of food player eats per day, affects radPointsCalc -export var path = 0; // Path player is currently on, 0 = Main, 1 = A, 2 = B -export var location = 0; // Location on main path, 0-255 = main, 500-1000 = A, 1500-2000 = B -export var locationA = 0; // Location on path A -export var locationB =0; // Location on path B +global.path = 0; // Path player is currently on, 0 = Main, 1 = A, 2 = B +global.location = 0; // Location on main path, 0-255 = main, 500-1000 = A, 1500-2000 = B +global.locationA = 0; // Location on path A +global.locationB =0; // Location on path B -export var reputation = {mwbos: 4, legion: 4, ncr: 2, bos: 1, enclave: 10, abomination: 0, raider: 0} +global.reputation = {mwbos: 4, legion: 4, ncr: 2, bos: 1, enclave: 10, abomination: 0, raider: 0} // Rep for each faction. Number between 0(worst) and 10(best), 5 is neutral -export var daysSinceScav = 0; // Days since player last scavenged. Must be >= 15 to scavenge again. +global.daysSinceScav = 0; // Days since player last scavenged. Must be >= 15 to scavenge again. -export var name = "placeholder"; // Player name, changed when the game starts +global.name = "placeholder"; // Player name, changed when the game starts export function variableChange(variable, operation, value) { switch(operation) {