I am making a .hta game and I have asked on many websites for help but nothing. when I run this script I get a undefined error so please help.
<application>
<head>
<title>Sample game</title>
</head>
<body>
<h1>Hello and welcome to the death tbg(text-based-game) just answer each question and see what you get!</h1>
<div id="question"></div>
<div id="answers"></div>
<embed src="expl.mp3" autostart="true" loop="true"
width="2" height="0">
</embed>
<script>
var db = [
{ //0
"question":"You wake up in a dark room no light all but faint shadows dancing around the room. As you move around trying to find your way you find a switch what do you do?",
"answers":[
{"title":"Turn it on","response":1},
{"title":"Shit your pants","response":2},
{"title":"Scream","response":3},
{"title":"Run like mad","response":4},
]
},
{ //1
"question":"KABOOM!!! Just kidding all you see is a cage a knife and a dead body.",
"answers":[
{"title":"A DEAD BODY?!?!?!","response":5},
{"title":"noice","response":6},
{"title":"Check to see who it is like a real detective","response":7},
]
},
{ //2
"question":"OMG why did you shit your pants you scrub.",
"answers":[
{"title":"You better know the key to speed(SPEEED IS KEEEEEEEEEEEEEEEY!!!!!!)","response":8},
{"title":"Well not much to say really.","response":9},
{"title":"You get humiliated. You try to run but your poop slips out of your pants and kills you.","response":10},
]
},
{ //3
"question":"Nice Scream. Now what",
"answers":[
{"title":"You screamed. No one is there. No one can save you.","response":11},
{"title":"Your such a girl.","response":12},
]
},
{ //4
"question":"You run into a killer.",
"answers":[
{"title":"Go ham","response":13},
{"title":"Dance","response":14},
{"title":"kill him??","response":15},
]
},
{ //14
"question":"You try to kill him",
"answers":[
{"title":"Gouge ","response":16},
{"title":"","response":17},
{"title":"","response":18},
]
}
];
var currentLocation = 0;
window.printCurrentLocation = function(){
document.getElementById("question").innerHTML = db[currentLocation].question;
var answers = "";
for(var i=0,l=db[currentLocation].answers.length;i<l;i++){
answers += "<p><button onclick='setLocation("+db[currentLocation].answers.response+")'>"+db[currentLocation].answers.title+"</button></p>";
}
document.getElementById("answers").innerHTML = answers;
}
window.setLocation = function(num) {
currentLocation = num;
window.printCurrentLocation();
}
window.printCurrentLocation();
</script>
</body>
</application>
Comments
1: This forum is for discussing games made using Twine
2: When you build up the response buttons you're not telling it which answer to display the text for. you have the line
when it should be
3: From the looks of it, you could quite easily make your game in Twine and it'd have a lot less boilerplate code.
But again, you're more likely to get helpful answers on a site that's dedicated to javascript problems.