Message in Response to Button Press

Hi.
I'm working on a game where the player asks for a hint by pressing the 'h' key and getting hints as they go, so basically whenever they press on 'h' they get a new hint, how do I do that exactly?

3 commentaires

Jan
Jan le 11 Avr 2021
It depends. Are you creating a GUI with GUIDE, AppDesigner or programmatically with a figure or uifigure? Or are you working in the command window?
Ghina Alhunaidi
Ghina Alhunaidi le 11 Avr 2021
Modifié(e) : Walter Roberson le 11 Avr 2021
So far I'm just working with figures, but I'm introducing GUI/pop-ups. So basically, the players get a file with a video and a pop-up window pops up telling them to input their guesses for the "code", but I want them to be able to press h to ask for hints even while the pop-up window is there, is that possible?
This is what i have for my code so far just so you can understand the initial concept i guess:
welcome=["welcome message"];%write later
title(welcome,'fontweight','bold','fontsize',15)
waitforbuttonpress;
Cellwindow = imread('window.jpeg');
imshow(Cellwindow, 'InitialMagnification',3000)
welcome = ['looks like..'];
title(welcome,'fontweight','bold','fontsize',15)
waitforbuttonpress;
%code to open puzzle folder
code1 = inputdlg('Please enter the Letter Block Puzzle code:');
while ~strcmp(code1,'53214')
disp('please try again')
code1 = inputdlg('Please enter the Letter Block Puzzle code:');
end
disp('Next puzzle unlocked!')
Walter Roberson
Walter Roberson le 11 Avr 2021
When you use inputdlg() then by default it creates a new figure for the interaction and it uses windowstyle 'modal'. The new figure does not have any key press callbacks you might have established, and the 'modal' does not return until the dialog is finished so you cannot activate any other window to allow the other window's controls to come into effect.
In theory you could deliberately tell it window style 'normal' instead of modal, and then in theory you could find the figure and inject callbacks into it so that pressing h coudl work. But the situation is not defined for that.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Number games dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by