Adad Dayos
Adad Dayos

Reputation: 761

MATLAB: how to make my function wait for GUI input

I am trying to make a GUI for a tic tac toe game I made. Here is the code I have for the GUI so far:

function fig=TTTGUI()for 

close all
%initial creation

fig=figure('pos',[100 50 820 640]);
txtbx=uicontrol('style','text','parent',fig,'pos',[640 320 160 300]);
B0=uicontrol('style','pushbutton','parent',fig,'pos',[640 200 40 40],'string',0);
B1=uicontrol('style','pushbutton','parent',fig,'pos',[680 200 40 40],'string',1);
B2=uicontrol('style','pushbutton','parent',fig,'pos',[720 200 40 40],'string',2);
B3=uicontrol('style','pushbutton','parent',fig,'pos',[760 200 40 40],'string',3);

%set number of players
players=[];
set(txtbx,'string','how many players? (1 or 2)');
set(B1,'callback','players=1;');
set(B2,'callback','players=2;');
%stop and wait here

end

I want all of my functions to stop at this point and wait until the variable players changes, which only happens from button 1 or 2 being presses.

I have looked at 'waitfor', 'uiwait', 'pause', and a couple other functions but I can't find what I am looking for. Or maybe I dont quite understand how to use those functions. How do I make my functions wait for one of those 2 buttons to be pressed? If another button is pressed, it should have no effect.

Upvotes: 1

Views: 1827

Answers (1)

Shai
Shai

Reputation: 114786

Try using a pre-defined question dialogbox. See here for more details.

button = questdlg('How many players?', 'One', 'Two' );

Upvotes: 2

Related Questions