Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code running when a window is on screen

Status
Not open for further replies.

Piccolo3000

Programmer
Oct 17, 2006
1
0
0
CA
Hello,

I don't know if it's very descriptive :) I'm writing a chess program in C++ interfaced with tcl/tk for graphics; I'm at the end, but there is a last bug:

when a player put a pawn on the last rank, it promotes in queen, knight, bishop or rook; so I had to show a window to let the choice to the player. It works well, but when the player is choosing his piece, the code go on running and the computer plays before knowing the player's choice !

Here is a schema of my code:

# inside the procedure "play a move", there is:

proc Promotion {
# show window .promotion,
# with commands "SelectPiece .."
}

proc SelectPiece {
# destroy window .promotion
# modify the board and return to the calling procedure
# ("play a move")
}

# back inside "play a move" : return "move is OK" :)

It seems that the computer executes "return move is OK" before the SelectPiece procedure is over.
Why? And.. What can I do to correct this? I've no idea, I'm beginner in tcl/tk.

Thanks,
Benjamin.
 
Just for completeness, vwait, on the Tcl side, does the same thing:
SYNOPSIS
vwait varName


DESCRIPTION
This command enters the Tcl event loop to process events, blocking the application if no events are ready. It continues processing events until some event handler sets the value of variable varName. Once varName has been set, the vwait command will return as soon as the event handler that modified varName completes. varName must globally scoped (either with a call to global for the varName, or with the full namespace path specification).

In some cases the vwait command may not return immediately after varName is set. This can happen if the event handler that sets varName does not complete immediately. For example, if an event handler sets varName and then itself calls vwait to wait for a different variable, then it may not return for a long time. During this time the top-level vwait is blocked waiting for the event handler to complete, so it cannot return either.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top