Changing things on the front-end
Sun Dec 12 2021 10:42:54 GMT+0000 (Coordinated Universal Time)
Saved by @vincentleoooo #javascript
// One of the functions that react to the dropdown menus being changed and // to prevent duplicate stations. function onChange1() { if (isRunning || isPaused) { alert( "Please reset the model first before changing this parameter. Changing the parameter will reset the simulation." ); } else { var choice1 = document.getElementsByName("choices1")[0].value; if (choice1 == "none") { let position2 = getKeyByValue(positions, 2); positions[position2] = 0; } else { let position2 = getKeyByValue(positions, 2); let position3 = getKeyByValue(positions, 3); let position4 = getKeyByValue(positions, 4); if (choice1 == position3 || choice1 == position4) { alert("Duplicates found. Please choose a different station."); let select = document.querySelector("#select1"); select.value = "none"; } else { positions[choice1] = 2; } positions[position2] = 0; } redrawWindow(); } } // Function to track changes in the input value boxes. function changeProb() { if (isRunning || isPaused) { alert( "Please reset the model first before changing this parameter. Changing the parameter will reset the simulation." ); } else { probArrival = 1 / Number(document.getElementById("probArrival").value); probImmigration = 1 / Number(document.getElementById("probImmigration").value); probTesting = 1 / Number(document.getElementById("probTesting").value); probCovid = Number(document.getElementById("probCOVID").value); testingTime = Number(document.getElementById("timeTest").value); probFindBaggage = Number(document.getElementById("probBaggage").value); animationDelay = Number(document.getElementById("animationDelay").value); passengerCount = Number(document.getElementById("passengerCount").value); simulationRuns = Number(document.getElementById("simulationRuns").value); randomChosenQueue = Number( document.getElementById("randomChosenQueue").value ); } } // Value safety for the input boxes function runSim() { let choice1 = document.getElementsByName("choices1")[0].value; let choice2 = document.getElementsByName("choices2")[0].value; let choice3 = document.getElementsByName("choices3")[0].value; isPaused = false; changeProb(); if (choice1 == "none" && choice2 == "none" && choice3 == "none") { alert("Please make at least one station choice."); } else if (isRunning) { alert("Already running."); } else if ( isNaN(probArrival) || isNaN(probCovid) || isNaN(probImmigration) || isNaN(probTesting) || isNaN(probFindBaggage) || isNaN(testingTime) || isNaN(animationDelay) || isNaN(passengerCount) || isNaN(simulationRuns) || isNaN(randomChosenQueue) ) { alert("At least one of the inputs is not a number."); } else { isRunning = true; simTimer = window.setInterval(simStep, animationDelay); } }
Comments