A fellow by the name of Cyriacus, in Ljubljana, Slovenia solved my problem for me. The cause of the problem was truly stupid (as most programming problems are). Here’s the line of code that was screwing everything up:
theEncounter.hasBeenUsed = true;
Do you see anything wrong with this? I certainly didn’t. The problem is that JavaScript doesn’t have anything like variable typing. In every other language since about 1980, you had to declare whether a variable was an Integer, a Floating Point number, a String, a Boolean, or something else. That kept everything neat and clean. But JavaScript is such an advanced language that it doesn’t permit you to declare variable types; it just decides what they are for you. Now, I preload all the values of my state variables using the standard JSON data structure. That data structure treats everything as a string. So when it initialized the values of that variable, it initialized it to ‘true’. Not true, ‘true’. Not a boolean value, a String value. The correct statement should read:
theEncounter.hasBeenUsed = 'true’;
This is the kind of thing that makes me want to buy a bunch of guns and ammo and storm into the offices of whomever designed JavaScript, spraying bullets right and left before killing myself.
What now?
This leaves me with an interesting problem: what do I do now? I’ve struggled against this problem for so long that I’ve lost sight of the larger issues, and I need to step back and consider the state of the project and what needs to be done next. Here are some of the things I could work on:
1. Learn WebStorm. This is the development environment that Jonathan Beyrak-Lev recommended to me. It looks very nice, and I would certainly like to get away from using a simple text editor to work on this project. But it looks like a lot of work.
2. Write more Encounters. I have about 60 written so far, and I need at least 200. I’ve pretty well finished all the ‘getting to know you’ encounters. Now I need encounters that permit interaction with the characters. Then I’ll need encounters covering the campaigns against the Saxons, in which Arthur must prove his martial skills. Lastly I’ll need the encounters for the endgame: Mordred’s revolt.
3. Clean up the code. The HTML uses tables for page layout, a minor no-no. The JavaScript is still pretty messy.
4. Integrate the face display code into the JavaScript. This will allow smooth transitions between the three pValues towards Arthur.
5. Write encounters testing promises and trust in Arthur.
Eeny, meeny, miny, moe.