Posted: Wed May 11, 2011 10:38 pm Post subject: 3 Piano keys don't work?
Well I making a piano game for my class, that plays all the notes of the white piano keys however, only 3 out of 7 actually work.
I checked my work yet I can't find anything wrong with it can you please help?
Also the notes that play in turing sound cut off can anyone tell me how to fix that?
Please and Thank you in Advance!
MY CODE!
% This program creates a fixed button box (button) on the screen and displays
% "You have just pressed the button" when the mouse button is pressed.
% Sets the screen to VGA graphics mode.
setscreen ("graphics.vga")
% Declares the button positions coordinates as constants.
const keyc_x1 :=100
const keyc_y1 :=100
const keyc_x2 :=150
const keyc_y2 :=300
loop
% Gets the mouse cursor status
mousewhere(xmouse,ymouse,button)
if button=1 and xmouse>=keyc_x1 and xmouse<=keyc_x2 and ymouse>=keyc_y1 and xmouse<=keyc_y2 then
play("c")
elsif button=1 and xmouse>=keyd_x1 and xmouse<=keyd_x2 and ymouse>=keyd_y1 and xmouse<=keyd_y2 then
play("d")
elsif button=1 and xmouse>=keye_x1 and xmouse<=keye_x2 and ymouse>=keye_y1 and xmouse<=keye_y2 then
play("e")
elsif button=1 and xmouse>=keyf_x1 and xmouse<=keyf_x2 and ymouse>=keyf_y1 and xmouse<=keyf_y2 then
play("f")
elsif button=1 and xmouse>=keyg_x1 and xmouse<=keyg_x2 and ymouse>=keyg_y1 and xmouse<=keyg_y2 then
play("g")
elsif button=1 and xmouse>=keya_x1 and xmouse<=keya_x2 and ymouse>=keya_y1 and xmouse<=keya_y2 then
play("a")
elsif button=1 and xmouse>=keyb_x1 and xmouse<=keyb_x2 and ymouse>=keyb_y1 and xmouse<=keyb_y2 then
play("b")
end if
end loop
Sponsor Sponsor
Tony
Posted: Wed May 11, 2011 10:56 pm Post subject: RE:3 Piano keys don\'t work?
you could do something like
code:
put "playing C"
play("c")
to have visual debugging. It might be that you are never making it into inside the "broken" conditions. Then you'd need to figure out all of your variables values and what the if-statements evaluate to.
Posted: Wed May 11, 2011 11:03 pm Post subject: RE:3 Piano keys don\'t work?
i am not sure what you talking about?
vdemons
Posted: Wed May 11, 2011 11:13 pm Post subject: RE:3 Piano keys don\'t work?
And apparently my code cannot run the last three elsif statements for some reason, and i can;t find out why can you please help!
Tony
Posted: Wed May 11, 2011 11:17 pm Post subject: Re: RE:3 Piano keys don\'t work?
vdemons @ Wed May 11, 2011 11:13 pm wrote:
i can;t find out why can you please help!
Take one of the if-statements that doesn't work (or any, they all have the same mistake), and read it very carefully (this might be subtle). It might help to read it out-loud. What you have written isn't exactly what you meant to write.
Posted: Wed May 11, 2011 11:46 pm Post subject: RE:3 Piano keys don\'t work?
i trying but the three not working elseif statements are exactly the same as the ones that are working, so the problem is either the button=1, or the variables itself i.e. xmouse>=keya_x1 but i dont know how to fix it can you help i am not experienced enough.
Tony
Posted: Wed May 11, 2011 11:51 pm Post subject: RE:3 Piano keys don\'t work?
The ones that are working are working on accident. Don't look at them as "correct reference". Just look at the part that doesn't work in isolation.
Posted: Thu May 12, 2011 12:26 am Post subject: RE:3 Piano keys don\'t work?
The problem is that i got these "custom made buttons" for my teacher and was told to use them, so i don't know what to do if there wrong.
Sponsor Sponsor
vdemons
Posted: Thu May 12, 2011 12:27 am Post subject: RE:3 Piano keys don\'t work?
This was his example:
% This program creates a fixed button box (button) on the screen and displays
% "You have just pressed the button" when the mouse button is pressed.
% Sets the screen to VGA graphics mode.
setscreen ("graphics.vga")
% Declares the button positions coordinates as constants.
const BUTTON_X1 :=60
const BUTTON_Y1 :=60
const BUTTON_X2 :=120
const BUTTON_Y2 :=120
% Declares the mouse varibles
var xmouse, ymouse, button:int
% Draws the box on the screen
drawbox(BUTTON_X1,BUTTON_Y1,BUTTON_X2,BUTTON_Y2,15)
loop
% Gets the mouse cursor status
mousewhere(xmouse,ymouse,button)
% Keeps looping until the coordinates of the mouse are within
% button's coordinates and the mouse button is pressed
exit when button=1 and xmouse>=BUTTON_X1 and xmouse<=BUTTON_X2 and ymouse>=BUTTON_Y1 and xmouse<=BUTTON_Y2
end loop
put "you have pressed the button"
Tony
Posted: Thu May 12, 2011 12:49 am Post subject: RE:3 Piano keys don\'t work?
doesn't work. Do you think you can help me fix that.
DemonWasp
Posted: Thu May 12, 2011 8:02 am Post subject: RE:3 Piano keys don\'t work?
You're testing "xmouse" against Y coordinates in all of your if / elsif conditions. The fact that 3 of them work is a coincidence based on their position.
Tony
Posted: Thu May 12, 2011 9:29 am Post subject: Re: RE:3 Piano keys don\'t work?
@DemonWasp -- way to put it out there so bluntly
@vdemons -- you were on the right path towards figuring things out
vdemons @ Thu May 12, 2011 6:42 am wrote:
i figured something out, for some reason any box further down the x-axis...
Posted: Thu May 12, 2011 9:55 am Post subject: RE:3 Piano keys don\'t work?
@Tony: Yeah, it was a bit blunt of me. But then, his teacher's code has the exact same bug in it, which makes this a lot more frustrating for a beginner to debug. He still has to figure out how to fix it (you'd think / hope that's trivial but experience with beginner programmers says otherwise) and potentially report the bug to the teacher.