How to assign points based on a key click

2 ビュー (過去 30 日間)
Julia Dunn
Julia Dunn 2019 年 12 月 4 日
コメント済み: darova 2019 年 12 月 4 日
Hello! Working on a guitar hero-esque code and we are trying to assign a user points based on the key they click. My problem is the variable points will not update outside of the inner function (titled dowhenkeyispressed) This is our code so far:
function p = pointsE(yPressed)
%returns the number of points the user earned given the yposition of when
%the user pressed the button
yTarget = 0;
difference = yPressed - yTarget; %difference in yposition
points = 0;
function dowhenkeyispressed(~,eventdata)
if eventdata.Character == 'e'
%0.1 - 0.3 = early
%-0.1 - 0.1 = on time
%-0.3 - -0.1 = late
if difference > 0.1 && difference <= 0.3
disp('early')
points = 50;
elseif difference >= -0.1 && difference <= 0.1
disp('on time')
points = 100;
elseif difference >= -0.3 && difference < -0.1
disp('late')
points = 50;
else
disp('no points')
points = 0;
end
close
elseif eventdata.Character ~= 'e'
points = 0;
disp('wrong button')
close
end
end
hFig = figure('Units','Normalized','OuterPosition',[0 0 0 0]);
set(hFig, 'KeyPressFcn', @dowhenkeyispressed);
p = points;
end
any advice? thanks!
  3 件のコメント
Julia Dunn
Julia Dunn 2019 年 12 月 4 日
what about for pressing a key on the keyboard?
darova
darova 2019 年 12 月 4 日
What is the variable yPressed equal to? Variable difference doesn't change inside the function

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by