Iām making a computer bot game that has two modes activated by a toggle. A random player mode and the hard mode where the bot actually plays by a given set of rules. I have both logics in two different js files. I want the html to reference either one depending on if a switch is active. How would I do this?
Asked
Active
Viewed 44 times
0
-
3please provide [mcve] of your code ā depperm Jul 12 '19 at 13:56
-
You can do an `eval()` of script1.js in one case and script2.js in the other case - https://stackoverflow.com/questions/12917348/read-file-with-fs-readfilesync-and-eval-contents-which-scope-have-the-function ā C00kieMonsta Jul 12 '19 at 14:01
-
1Possible duplicate of [Calling a javascript function in another js file](https://stackoverflow.com/questions/25962958/calling-a-javascript-function-in-another-js-file) ā mahan Jul 12 '19 at 14:06
1 Answers
1
Unfortunately you did not provide an example but assuming you want to switch between logic based on the running mode this could help you.
const hardmode = true
const logicForNormalMode = {
doSomething: function(){
console.log("Normalmode => Something done")
}
}
const logicForHardMode = {
doSomething: function(){
console.log("Hardmode => Something done")
}
}
const logic = hardmode ? logicForHardMode : logicForNormalMode
logic.doSomething()