Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Waiting for user input - Gideros Forum

Waiting for user input

qxmat2qxmat2 Member
edited November 2017 in General questions
Hi there!

I am programming a little card game for learning purposes. I stepped into a little problem, where I don't know the best practice howto solve it.

If the player (me) throws a certain card, an additional dialog pops up and asks the player which face (spades, diamonds...) he wants from the opponent as the next card, so the opponent is forced to serve this face.

The pseudo code looks like this
function playerMove(playercards, opencardOnStack){
  foreach(playercards as card){
    if(card==opencardOnStack){ success=1; playerWantToThrowthisCard=card }
  }
 
  if(success==1){
    if(playerWantToThrowthisCard == "Jack"){ -- the Jack is the special card which enables the player to wish a face from the opponent
 
     doWait = true
 
      dialog = Dialog
      dialog:addEventListener("click", function(){ print("clicked"); doWait=false}
      dialog:showDialog(wishedFaceFromOpponent = function(){ print("which face do you want from the opponent"); return function readFace() }
 
      while doWait==true
      end
 
      print("the player wants the opponent to throw a" .. wishedFaceFromOpponent)
 
    }
 
  }
  nextPlayersTurn()
}
So I have implemented a kind of "active waiting" which is bad programming practise and additionally it doesn't work, because it hangs my simulator.

Of course I could pack the further statements, which should be executed after "clicked" into that event listener, but that doesn't work with my code well, because it consists of many nested subroutines, beside that it would branch my code even more. For this to work, I'd had to completely redesign my code only for this single purpose, that cannot be the only solution.

I googled but cannot seem to find the right way to do this. The function I'm seeking for is something like waitForEventCompleted(), which halts the further execution as long as the user clicked something in the dialog. This functions should substitute the "while doWait==true end" active wait statement. I guess this "waiting" thing is something different in event-driven environments.

Comments

Sign In or Register to comment.