Game of Life GUI Question

조회 수: 1 (최근 30일)
Jacob Huhtala
Jacob Huhtala 2019년 4월 3일
댓글: Jacob Huhtala 2019년 4월 3일
I have been making a GUI to be an assistance program for The Game of LIFE by milton bradley. While doing this I have had some issues using pop up boxes to let the player select if they want to go to college at the start of the game. Here is the code I use to retreive the data out of the popup and bring it into the code so I can determine amount of career options for the player. Then after that is my push button to randomly pick your career. Everytime I try to excute this I get the error "Undefined function or variable 'collegechoice'.
Error in sblife>pfc1_Callback (line 337)
if collegechoice == 1
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in sblife (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)sblife('pfc1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback."
function pbcollege1_Callback(hObject, eventdata, handles)
q=cellstr(get(hObject,'String'));
z=q{get(hObject,'Value')};
if (strcmp(z,'Select Choice'))
collegechoice=0;
elseif (strcmp(z,'No, Skip College'))
collegechoice=2;
elseif (strcmp(z,'Yes, Go To College'))
collegechoice=1;
end
assignin('base','collegechoice',collegechoice);
function pbcollege1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%push button for career
function pfc1_Callback(hObject, eventdata, handles)
if collegechoice == 1
careers = randi(9);%used for if they selected yes from popup box
set(handles.careerbox1,'Doctor');%just a place holder for when I actually get it working
end

채택된 답변

Steven Lord
Steven Lord 2019년 4월 3일
Would it be easier for you to use a questdlg dialog?
  댓글 수: 4
Steven Lord
Steven Lord 2019년 4월 3일
Rather than putting code and controls in your GUI to ask the question, call questdlg to open a small dialog box and just use its output argument.
Jacob Huhtala
Jacob Huhtala 2019년 4월 3일
I got it thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conway's Game of Life에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by