rando-idiot / Terminus.JS

A somewhat small incremental game played in a web terminal.
Creative Commons Zero v1.0 Universal
0 stars 1 forks source link

Global scope game state storage #11

Open Bleb1k opened 3 hours ago

Bleb1k commented 3 hours ago

Storing the state of the game in global scope is a bad practice

https://github.com/rando-idiot/Terminus.JS/blob/bbd663f897dfff103f71800e38337470a8ad2b7d/terminus.js#L31-L41

users have full access to these variables this way, this leads to a really messy environment

Bleb1k commented 2 hours ago

i can have access to those variables by typing this in the console:

basegain: 1
​
baseup: function baseup()​
begin: function begin()
​
beginbought: 0
​
configYML: function configYML()
​
configymlbought: 0
​
doctype: function doctype()
​
doctypebought: 0
​
helloworld: function helloworld()​
index: function index()
​
indexbought: 0
​
info: function info()​
infshop: function infshop()
​
infunlock: 0
​
points: 0
​
push1: function push1()​
push2: function push2()​
shop: function shop()​
sleep: function sleep(milliseconds)​
stepfour: function stepfour()​
stepfour2: function stepfour2()
​
stepfouradd: 1
​
stepone: function stepone()​
stepone2: function stepone2()
​
steponeadd: 0
​
stepthree: function stepthree()​
stepthree2: function stepthree2()
​
stepthreemult: 1
​
steptwo: function steptwo()​
steptwo2: function steptwo2()
​
steptwomult: 1
​
update: function update()
​
updateloop: 1
​
upgbonus: function upgbonus()
​
upgbonusvar: 1
​
upgpriceboost: 0
​
upgstage: 0
Bleb1k commented 2 hours ago

this is fixed by using let instead of var

Bleb1k commented 2 hours ago

What is the difference between "let" and "var"?