Hello helpful users and professionals,
I have the misfortune of creating a GUI without any knowledge of how to do so. After watching the videos and summaries I just can't wrap my head around transporting handles between functions.
Below is my current code that I have. I commented it into submission so it would perform a very basic operation of updating the figure window by making the left and right patches (dark brown segments) slowly reduce in size from top to bottom. It works as written if I copy and paste each function into the command window, but clicking run shows (I assume) that the function 'refreshFIG' is not getting WALL_L and WALL_R from the function 'showFIGWINDOW'. Clicking RUN will get the error "Too few input arguments (line 115)" I assume the problem is the function is not getting the 'YData' from WALL_L or WALL_R. Any help one of you nice people can give me to correct this would be a huge assist as I am exhausted by this problem.
CURRENT WORK IS AS FOLLOWS:
function Canyon_Racerclose allclearclcWIDTH_LIMIT=.005; %CONTROLS RATE OF WALL CLOSURE
DROP_COUNT=5;CWALL_L1=0;CWALL_L2=0;CWALL_L3=1;CWALL_L4=1;CWALL_L5=0;CWALL_L6=30;CWALL_L7=30;CWALL_L8=0;CWALL_R1=14;CWALL_R2=14;CWALL_R3=16;CWALL_R4=16;CWALL_R5=0;CWALL_R6=30;CWALL_R7=30;CWALL_R8=0;CWALL_Y=30;CLOSE=2;CWALL_LMAX=1;CWALL_RMIN=14;CWALL_TMAX=30;DELAY=.25;POLY_NUM=1;WALL_WIDTH=14;gameEND=0; %causes game to intiate and continue
% TITLE = ['Welcome to CANYON RUN' 10 10 ' Out run the bandits on your tail to sruvive!' 10 10 '...but don' 10 10 'crash into the canyon walls or you' 10 10 're history' 10 10
% ' player 1: player 2:' 10 10 ' use (LEFT) and (RIGHT) arrow keys to stay between the walls' 10 10];
function showFIGWINDOW scrsz = get(0,'ScreenSize'); fig = figure('Position',[0, 0, 1, 1]); set(fig , 'Units', 'Normalized', 'OuterPosition', [0 0 .75 .75], 'color', [127 84 23]./255); %display full screen
% CanyonWallX_L = [CWALL_LMIN CWALL_LMAX];
% CanyonWallX_R = [CWALL_RMIN CWALL_RMAX];
subplot('position', [0 0 1 1]) axis([0 15 0 30]) hold all WALL_L = patch([CWALL_L1 CWALL_L2 CWALL_L3 CWALL_L4], [CWALL_L5 CWALL_L6 CWALL_L7 CWALL_L8], [0 0 0], 'edgecolor', 'none'); WALL_R = patch([CWALL_R1 CWALL_R2 CWALL_R3 CWALL_R4], [CWALL_R5 CWALL_R6 CWALL_R7 CWALL_R8], [0 0 0], 'edgecolor', 'none'); set(WALL_L, 'FaceColor', [127 84 23]./255) set(WALL_R, 'FaceColor', [127 84 23]./255) set(gca, 'XTick', [],'YTick', [], 'color', [184 95 0]./255) set(fig,'Name','Canyon Racer v1.0','NumberTitle','off', 'toolbar', 'none', 'menubar', 'none') movegui(fig,'center'); RACER_handle = patch([5 6 5.5], [3 3 5.5], [0 0 0]); %%%Check this for uicontrol stuff: http://www.mathworks.com/help/matlab/ref/uicontrol.html
TBX = uicontrol( 'style', 'edit', 'String', 'Hi', 'Position', [.5, .5, 100.5, 15.5] );%%%%%%%DR. V
%%%Check out the "KeyPressFcn/KeyReleaseFcn portion of this:
%%%http://www.mathworks.com/help/matlab/ref/figure_props.html
set(fig, 'KeyPressFcn', {@KeyPressed, TBX, RACER_handle} ) %%%%%%%DR. V set(fig, 'KeyReleaseFcn', {@KeyReleased, TBX}) %%%%%%%DR. V end function newGame end function KeyPressed( src, event, TBX, RACER_handle) %%%%%%%DR. V set( TBX, 'String', sprintf('%s Pressed', event.Key ) );%%%%%%%DR. V if strcmp(event.Key, 'leftarrow') MOVE_handle = get(RACER_handle,'XData'); set(RACER_handle, 'XData', MOVE_handle-.1 ); elseif strcmp(event.Key, 'rightarrow') MOVE_handle = get(RACER_handle,'XData'); set(RACER_handle, 'XData', MOVE_handle+.1 ); end end %%%%%%%DR. V function KeyReleased( src, event, TBX) %%%%%%%DR. V set( TBX, 'String', sprintf('%s Released', event.Key ) );%%%%%%%DR. V end %%%%%%%DR. V function refreshFIG( src, event, WALL_L, WALL_R) pause(DELAY) SPEED_MOVE=1; % if DROP_COUNT==5
%
% CWALL_L3=randi(CLOSE);
% while CWALL_L3>CLOSE
% CWALL_L3=randi(CLOSE);
% end
% if POLY_NUM==0
% WALL_L = patch([0 0 CWALL_L3 CWALL_L4], [CWALL_Y CWALL_Y+5 CWALL_Y+5 CWALL_Y], [0 0 0], 'edgecolor', 'none');
% WALL_R = patch([CWALL_L4+WALL_WIDTH CWALL_L3+WALL_WIDTH 15 15], [CWALL_Y CWALL_Y+5 CWALL_Y+5 CWALL_Y], [0 0 0], 'edgecolor', 'none');
% set(WALL_L, 'FaceColor', [127 84 23]./255)
% set(WALL_R, 'FaceColor', [127 84 23]./255)
% CWALL_L4=CWALL_L3;
% elseif POLY_NUM>0
% WALL_L = patch([0 0 CWALL_L3 CWALL_L4], [CWALL_Y CWALL_Y+5 CWALL_Y+5 CWALL_Y], [0 0 0], 'edgecolor', 'none'); % WALL_R = patch([CWALL_L4+WALL_WIDTH CWALL_L3+WALL_WIDTH 15 15], [CWALL_Y CWALL_Y+5 CWALL_Y+5 CWALL_Y], [0 0 0], 'edgecolor', 'none'); % set(WALL_L, 'FaceColor', [127 84 23]./255) % set(WALL_R, 'FaceColor', [127 84 23]./255) % CWALL_L4=CWALL_L3; % end % if POLY_NUM==6
% POLY_NUM=1;
% end % % end
DROP_WALL_L = get(WALL_L, 'YData'); set(WALL_L, 'YData', DROP_WALL_L-SPEED_MOVE) DROP_WALL_R = get(WALL_R, 'YData'); set(WALL_R, 'YData', DROP_WALL_R-SPEED_MOVE) % for NUM=(1:POLY_NUM)
% DROP_WALL_L = get(WALL_L(NUM), 'YData');
% set(WALL_L(NUM), 'YData', DROP_WALL_L-SPEED_MOVE)
% DROP_WALL_R = get(WALL_R(NUM), 'YData');
% set(WALL_R(NUM), 'YData', DROP_WALL_R-SPEED_MOVE)
% end POLY_NUM=POLY_NUM+1; % DROP_COUNT=DROP_COUNT+1;
% CWALL_LMAX=CWALL_LMAX+WIDTH_LIMIT; %LEFT WALL CLOSING IN
% CWALL_RMIN=CWALL_RMIN-WIDTH_LIMIT; %RIGHT WALL CLOSING IN
% WALL_L = patch([0 CWALL_LMAX], [CWALL_TMAX CWALL_TMAX]); %POST TO FIG WINDOW
% WALL_R = patch([CWALL_RMIN, 15], [CWALL_TMAX CWALL_TMAX]); %POST TO FIG WINDOW
% set(WALL_L, 'FaceColor', [127 84 23]./255) %FIG WALL AREA COLOR
% set(WALL_R, 'FaceColor', [127 84 23]./255) %FIG WALL AREA COLOR
end%Game Primary Script
showFIGWINDOWnewGamewhile gameEND==0 % moveWall;
refreshFIG; % checkWALL;
end% close(fig);
%
%end
Best Answer