i have written a code which creates a figure with 3 buttons and a text box. the program complains about my callback function when i press a button though.
function game(states)
fig=figure('position',[200 150 500 370]);
face.B1=uicontrol('parent',fig,'style','pushbutton','string','start!','visible','on','position',[20 160 460 50]);
face.B2=uicontrol('style','pushbutton','parent',fig,'string','B2','visible','off','position',[20 90 460 50]);
face.B3=uicontrol('style','pushbutton','parent',fig,'string','B3','visible','off','position',[20 20 460 50]);
face.txtbx=uicontrol('style','text','parent',fig,'string','welcome to my game. press start to begin','position',[20 230 460 120]);
%set the callback function of the button
%when the button is pressed, i want to initiate the changestate function
set(face.B1,'callback','changestate(face,states,1);');
% while 1
uiwait(fig)
% end
end
this is the function that i want to call when the button is pressed. the contents of this function are not important to my question, but i include it just in case
function face = changestate(face,states,nextstate)
disp('enter changestate')
face.B1=set(face.B1,'string',states{nextstate}.B1str,'callback','changestate(face,states,states{nextstate}.B1next)');
if ~isnan(states(nextstate).B2str)
face.B2=set(face.B2,'string',states{nextstate}.B2str,'callback','changestate(face,states,states{nextstate}.B2next)','visible','on');
else face.B2=set(face.B2,'visible','off');
end
if ~isnan(states(nextstate).B3str)
face.B3=set(face.B3,'string',states{nextstate}.B3str,'callback','changestate(face,states,states{nextstate}.B3next)','visible','on');
else face.B3=set(face.B3,'visible','off');
end
face.txtbx=set(face.txtbx,'string',states{nextstate}.txtbxstr);
% uiresume(fig)
end
the error that i am receiving is:
Error using waitfor Undefined function or variable 'face'.
Error using waitfor Error while evaluating uicontrol Callback
this error occurs when i press the button B1. I want the button to initiate the changestate function. can someone explain to me why i am getting this error?