Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 3 Piano keys don't work?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
vdemons




PostPosted: 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

const keyd_x1 :=150
const keyd_y1 :=100
const keyd_x2 :=200
const keyd_y2 :=300

const keye_x1 :=200
const keye_y1 :=100
const keye_x2 :=250
const keye_y2 :=300

const keyf_x1 :=250
const keyf_y1 :=100
const keyf_x2 :=300
const keyf_y2 :=300

const keyg_x1 :=300
const keyg_y1 :=100
const keyg_x2 :=350
const keyg_y2 :=300

const keya_x1 :=350
const keya_y1 :=100
const keya_x2 :=400
const keya_y2 :=300

const keyb_x1 :=400
const keyb_y1 :=100
const keyb_x2 :=450
const keyb_y2 :=300

% Declares the mouse varibles
var xmouse, ymouse, button:int

% Draws the box on the screen
Draw.Box (keyc_x1,keyc_y1,keyc_x2,keyc_y2, 20)
Draw.Box (keyd_x1,keyd_y1,keyd_x2,keyd_y2, 20)
Draw.Box (keye_x1,keye_y1,keye_x2,keye_y2, 20)
Draw.Box (keyf_x1,keyf_y1,keyf_x2,keyf_y2, 20)
Draw.Box (keyg_x1,keyg_y1,keyg_x2,keyg_y2, 20)
Draw.Box (keya_x1,keya_y1,keya_x2,keya_y2, 20)
Draw.Box (keyb_x1,keyb_y1,keyb_x2,keyb_y2, 20)


Draw.FillBox (140, 180, 160, 300, 12)
Draw.FillBox (190, 180, 210, 300, 12)
Draw.FillBox (290, 180, 310, 300, 12)
Draw.FillBox (340, 180, 360, 300, 12)
Draw.FillBox (390, 180, 410, 300, 12)

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
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: 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




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: 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
Sponsor
sponsor
vdemons




PostPosted: 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




PostPosted: Thu May 12, 2011 12:49 am   Post subject: RE:3 Piano keys don\'t work?

try
code:

const BUTTON_X1 :=130
const BUTTON_Y1 :=60
const BUTTON_X2 :=190
const BUTTON_Y2 :=120

instead
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: Thu May 12, 2011 5:57 am   Post subject: RE:3 Piano keys don\'t work?

i don't get it, it dosen't anything not even allow button to be pressed?
vdemons




PostPosted: Thu May 12, 2011 6:42 am   Post subject: RE:3 Piano keys don\'t work?

Tony i figured something out, for some reason any box further down the x-axis from

const keye_x1 :=250
const keye_y1 :=100
const keye_x2 :=300
const keye_y2 :=300

doesn't work. Do you think you can help me fix that.
DemonWasp




PostPosted: 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




PostPosted: 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 Laughing

@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...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DemonWasp




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: