I am writing a text game in javascript, and one of the main “functions” is the input field, which accepts user input and sends the input with a button tag. In my main game loop, the onclick button is called:
var game_u = new game_util();
function Game_Main(){
while(active){
input = game_u.getText();
active = false;
}
}
function game_util(){
this.getText = function(){
confirm_plr.onclick = function(){
return player_in.value;
}
}
}
The problem with this path is that the while loop does not "wait" for the "Submit" button, which must be pressed in order to get input from `game_u.getText (); and continues the cycle.
Is there a better way for me to do this, is this my first mistake in a text game? I do not want to use the prompt method, because it violates the immersion in the gameplay.
I am also from Java, an object-oriented programming language, so I use a while loop.
Any help is appreciated.