0

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?

Zenn Magic
  • 11
  • 2
  • 3
    please 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
  • 1
    Possible 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 Answers1

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()