I'm putting together a kind of Narrated Role using Javascript.
I use a <input id="dialogo" type="text">
to place our answers around the situation that is happening in the "Adventure".
I take the data of <input>
when the user presses the "Enter".
var dialogo = document.querySelector('#dialogo');
dialogo.addEventListener('keydown', ComprueboDatos)
function ComprueboDatos(){
var tecla = event.key;
if(tecla == 'Enter'){ //Trate de poner 13 pero no me lo toma. (ASCII ENTER)
if(dialogo.value == "aventura"){
dialogo.value = ''
IniciaAventura()
}
else{
consola.innerHTML = "No entendi lo que me dijiste."
dialogo.value = ''
}
}
}
Now, when I want to confirm if you really want to start it, the idea is to rewrite the <input>
"yes" and start it.
function IniciaAventura() {
if(dialogo.value == 'si'){
consola.innerHTML = "Empezemos a explorar";
setTimeout(AventuraNro1, 2000);
}
if (dialogo.value == 'no') {
CancelaAventura();
}
else{
consola.innerHTML = "Vuelve cuando estes preparado."
}
}
But obviously I have 2 cases:
-
One is that you set
dialogo = ''
to delete the content that is written. -
And second, it's all linear. For more than write "adventure", I started the "adventure", passes the
dialogo
emptied without leaving me ami option to decide and ends in an else.
My question
How can I do to have more control within the loops and if in similar cases?
This example that I showed is not so much the problem, but imagine when you have to start describing the user if he decides to go east or west or other types of written actions.
I would need to constantly use <input>
and have it respond to me in the place I requested it.
Extra:
Investigate using Break and Continue, but do not find a solution with those commands.
I hope it has been clear, I hope you can give me a hand to guide me better.
It's my first big project with HTML, CSS / Sass / JS / Gulp / PHP / MySQL so I'm sure when I fall back into the well I'll ask again.
Thank you very much!