Ok, so me and a friend are making a JS game together. It's a God Game kinda thing in which the user uses resources to build houses and other buildings. IT IS IN VERY EARLY DEVELOPMENT!
I use variables as grid references, so they can be set to a certain building. e.g.:
var OneOne = none
So the grid would look like this:
- OneOne, OneTwo, OneThree
- TwoOne, TwoTwo, TwoThree
- ThreeOne, ThreeTwo, ThreeThree
My problem is somewhere in the building phase, I use a function called Build(type, loc)
that is used for adding a building to the map. I do this with a switch statement that looks at the loc
parameter and sets the corresponding grid reference to the value of the building. So if this.loc === OneOne
, then OneOne = this.type
.
The desired outcome of this script is to set OneOne to WoodHut.
In Theory, if you were to print off the grid line by line, having just done Build(WoodHut, OneOne)
, you should get something like:
- WoodHut, none, none
- none, none, none
- none, none, none
But this will not work! I can't really figure out why this isn't working... The REAL outcome i get is:
- none, none, none
- none, none, none
- none, none, none
Here is my source code: JS
And the HTML I use to run the script and the functions: HTML
Please have a read through them and spot my error! A hint or tutorial would be much appreciated. Thanks in advance!