0

So, I'm making a game on HTML Canvas using JavaScript. Long story short, there's a bunch of variables that are executed at the start of the game. Some of them define player speed or enemy damage etc. You get my point. Thing is, I would like to make a config.txt file that defines all the important variables, and then set up the code to read that txt file and assign variables their values based on that. How can I do it?

Most of the variables are integers, so it would need to transform what I assume would be a string to integers for it to work properly.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
tralph3
  • 452
  • 4
  • 13
  • See the duplicate question I linked at the top of your post. – Robert Harvey May 23 '19 at 00:06
  • @RobertHarvey It doesn't seem to answer my question, and if it does, I don't get it. – tralph3 May 23 '19 at 00:08
  • Put your items into a JSON file, and then read the file as illustrated. – Robert Harvey May 23 '19 at 00:10
  • 1
    See also https://www.w3schools.com/js/js_json_parse.asp – Robert Harvey May 23 '19 at 00:10
  • @RobertHarvey See if I understand correctly. I create a JSON file that contains all the variables definitions. Then I create a variable in JS like this var x = JSON.parse(config file route) and then I can define variables by using this: var some variable = x.configValue; Is this correct? If so this is insanely helpful and I thank you a lot, also, how does it differenciate between a boolean and a string? – tralph3 May 23 '19 at 00:18

0 Answers0