Button Errors
Author |
Message |
Shockdot
|
Posted: Sun Dec 21, 2008 10:54 am Post subject: Button Errors |
|
|
Hello, i am new to Turing and to this website...
I am having some problems with what i beleive to be a loop error...
Well i will tell you what happens.
My game is a quiz.
The main menu of my quiz has 4 buttons that i created... Well images with the area around the words as a button. Anyways.
I set them all to the right positions and everything with the code below i set the exit when blablablabla command and everything.
But when i play the game it takes several somtimes over 50 clicks for the button to work... I think it is a problem with my loop or possibily my images are lagging somthing up i don?t know i tryed everything so any help would be greattt....
this is the code i used for the buttons
Turing: |
%Here are the variables for the buttons section
var x: int
var y: int
var button: int
var choice: string :=""
loop
Mouse.Where (x, y, button )
if x=> # and x<= # and y=># and y<=# and button= 1 then
choice = PROCEDURE FOR THIS BUTTON GO HERE
end when choice not =""
elsif x=> # and x<= # and y=># and y<=# and button= 1 then
choice = PROCEDURE FOR THIS BUTTON GO HERE
end when choice not =""
elsif x=> # and x<= # and y=># and y<=# and button= 1 then
choice = PROCEDURE FOR THIS BUTTON GO HERE
end when choice not =""
elsif x=> # and x<= # and y=># and y<=# and button= 1 then
choice = PROCEDURE FOR THIS BUTTON GO HERE
end when choice not =""
end if
%Then i have in the middle of the screen Text saying to click a button that is changing color like so
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 1)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 2)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 3)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 4)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 5)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 6)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 7)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 8)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 9)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 10)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 11)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 12)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 13)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 14)
Delay (100)
Font.Draw ("Click A Button To Continue!", X-Position, Y-Position, Font, 15)
Delay (100)
end loop
|
Mod Edit: Code tags.
Ok Anyways that is my code also note there is a background image, all 4 buttons are images not Font.Draw commands..
All 5 of the images were put in with the code below.
Pic.ScreenLoad ("ImageName.bmp", X-Pos, Y-Pod, PicMerge)
Also i was wondering if anyone could direct me to a list of Fonts that turing allows you to use in the Font.Draw command. Please and ty.
Thanks to anyone who bothers to help me. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Clayton
|
Posted: Sun Dec 21, 2008 11:15 am Post subject: RE:Button Errors |
|
|
It would be much more helpful if you actually post your code that you're using, not some mashed together "example" code. |
|
|
|
|
|
Shockdot
|
Posted: Sun Dec 21, 2008 11:20 am Post subject: Re: Button Errors |
|
|
Ok here is the code
Turing: |
%Programming Bonanza!
%Ricardo Rodrigues
%December 8, 2008
%Do the quizzes, prove your the programming master!
%Variables go here
var x : int
var y : int
var button : int
var choice : string := ""
var name1 : string
var grade1 : int
var font : int
var response : string
var quiztype : int
var quiztype2 : string
var last : int
var tq1answer : real
var tq1answer2 : string
var tq2answer : int
var tq2answer2 : string
var tq3answer : int
var tq3answer2 : string
var tq4answer : int
var tq4answer2 : string
var tq5answer : int
var tq5answer2 : string
var tq6answer : int
var tq6answer2 : string
var tq7answer : int
var tq7answer2 : string
var tq8answer : int
var tq8answer2 : string
var tq9answer : int
var tq9answer2 : string
var tq10answer : int
var tq10answer2 : string
%Screen Settings Start
View.Set ("graphics:1000;650")
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
colorback (black)
color (white)
%Screen Settings End
%Fonts Start
font := Font.New ("BadaBoom BB:30")
%Fonts End
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%Procedures Start%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%Get User Information Start
procedure name
put "Welcome to Programming Bonanza!"
put "Please state first name."
get name1
end name
procedure grade %Get Users School grade
put "What grade are you in ", name1, "?"
get grade1
end grade
%Get User Information End
procedure StartProgram
name
grade
end StartProgram
procedure Index
cls
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
%Index Button Images Start
Pic.ScreenLoad ("Quiz.bmp", - 130, - 150, picMerge) %Quiz Start Image
Pic.ScreenLoad ("Instructions.bmp", 550, 420, picMerge) %Instruction Image
Pic.ScreenLoad ("Lessons.bmp", - 90, 420, picMerge) %Lessons Image
Pic.ScreenLoad ("Credits.bmp", 640, - 150, picMerge) %Credits Image
%Index Button Images End
loop
Mouse.Where (x, y, button )
if x >= 5 and x <= 200 and y >= 2 and y <= 80 and button = 1 then
choice := "quizselect"
exit when x >= 5 and x <= 200 and y >= 2 and y <= 80 and button = 1
elsif x >= 580 and x <= 990 and y >= 580 and y <= 700 and button = 1 then
choice := "instructions"
exit when x >= 580 and x <= 990 and y >= 580 and y <= 700 and button = 1
elsif x >= 5 and x <= 200 and y >= 580 and y <= 700 and button = 1 then
choice := "lessons"
exit when x >= 5 and x <= 200 and y >= 580 and y <= 700 and button = 1
elsif x >= 600 and x <= 990 and y >= 2 and y <= 80 and button = 1 then
choice := "credits"
exit when x >= 600 and x <= 990 and y >= 2 and y <= 80 and button = 1
end if
%Index Instructions start
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 1)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 2)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 3)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 4)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 5)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 6)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 7)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 8)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 9)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 10)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 11)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 12)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 13)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 14)
delay (100)
Font.Draw ("Please Click One Of The Four Buttons To Continue.", 75, 325, font, 15)
delay (100)
%Index Instructions end
end loop
end Index
%Index Page End
procedure QuizSelect %Quiz Start
cls
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
put "Please select your Quiz Type, by typing in the corresponding number."
put "1. Turing"
put "2. Alice"
put "3. HTML"
get quiztype
%Turing Quiz
if quiztype = 1 then
quiztype2 := "Turing"
cls
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing Question One Start
put "Question One"
put "What is the proper command to allow a user to input data into the program?"
put "1. say"
put "2. input"
put "3. enter"
put "4. put"
get tq1answer
if tq1answer = 4 then
tq1answer2 := "put"
put "Correct Answer!"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct answer was 4. put!"
delay (2000)
cls
end if
%Turing Question One End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing Question Two Start
put "Question Two"
put "Which is the correct list of variable types?"
put "1. string, int, tan"
put "2. tan, int, str"
put "3. real, int, str"
put "4. int, string, real"
get tq2answer
if tq2answer = 4 then
tq2answer2 := "int, string, real"
put "Correct Answer!"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct answer was 4. int, string, real!"
delay (2000)
cls
end if
%Turing Question Two End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing question Three Start
put "Question 3"
put "What is the improper way to input a variable name?"
put "1. clickme"
put "2. 28alpha"
put "3. answer"
put "4. amount"
get tq3answer
if tq3answer = 2 then
tq3answer2 := "28alpha"
put "Correct Answer"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct answer was 2. 28alpha"
delay (2000)
cls
end if
%Turing Question Three End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing Question Four Start
put "Question 4"
put "What command is used to set a background color?"
put "1. colorback (colorname)"
put "2. backgroundcolor (colorname)"
put "3. colorback (colornumber)"
put "4. back (colorname)"
get tq4answer
if tq4answer = 3 then
tq4answer2 := "colorback (colornumber)"
put "Correct Answer!"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct answer was 3. colorback (colornumber)"
delay (2000)
cls
end if
%Turing Question Four End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing Question Five Start
put "Question 5"
put "What command is commonly used to repeat areas of code?"
put "1. loop"
put "2. repeat"
put "3. cycle"
put "4. redo"
get tq5answer
if tq5answer = 1 then
tq5answer2 := "loop"
put "Correct Answer"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct answer was 1. loop"
delay (2000)
cls
end if
%Turing Question Five End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing Question Six Start
put "Question 6"
put "What command is used to make the program wait a certain amount of time?"
put "1. wait (amount)"
put "2. stop until (amount)"
put "3. delay (amount)"
put "4. standby (amount)"
get tq6answer
if tq6answer = 3 then
tq6answer2 := "delay (amount)"
put "Correct Answer!"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct Answer was 3. delay (ammount)"
delay (2000)
cls
end if
%Turing Question Six End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing Question Seven Start
put "Question 7"
put "When starting to create a program what should you always do before beginning the actual code?"
put "1. Make a introduction page."
put "2. Declare you're variables."
put "3. Place Comments such as programmers name, date, title of program, and description."
put "4. Check you're program for bugs."
get tq7answer
if tq7answer = 3 then
tq7answer2 := "Place Comments such as programmers name, date, title of program, and description."
put "Correct Answer!"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct answer was 3. Place Comments such as programmers name, date, title of program, and description."
delay (2000)
cls
end if
%Turing Question Seven End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing Question Eight Start
put "Question 8"
put "Some commands must be ended so that they can be completed. What is the first word used in all closing commands?"
put "1. close"
put "2. end"
put "3. exit"
put "4. leave"
get tq8answer
if tq8answer = 2 then
tq8answer2 := "end"
put "Correct Answer!"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct answer was 2. end"
delay (2000)
cls
end if
%Turing Question Eight End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing Question Nine Start
put "Question 9"
put "What command is used to clear a page of text?"
put "1. clear"
put "2. clean"
put "3. cls"
put "4. erase"
get tq9answer
if tq9answer = 3 then
tq9answer2 := "cls"
put "Correct Answer!"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct answer was 3. cls"
delay (2000)
cls
end if
%Turing Question Nine End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%Turing Question Ten Start
put "Question 10"
put "When working with Turing it is usually necessary for a program to have secondary options, such as yes or no. What command is used to program these decisions?"
put "1. if and or"
put "2. if and else"
put "3. if and elsif"
put "4. if and either"
get tq10answer
if tq10answer = 3 then
tq10answer2 := "if and elsif"
put "Correct Answer!"
delay (2000)
cls
else
put "Wrong Answer!"
put "The correct answer was 3. if and elsif"
delay (2000)
cls
end if
%Turing Question Ten End
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
%End Questions
%Begin Score Tally
%End Score Tally
%Begin Quiz Ending Page
%End Quiz Ending Page
%Alice Quiz
elsif quiztype = 2 then
quiztype2 := "Alice"
randint (last, 0, 10)
for decreasing count : 10 .. 0
delay (1000)
cls
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
put "You're Quiz will begin in 10 seconds"
put count
end for
%HTML Quiz
elsif quiztype = 3 then
quiztype2 := "HTML"
randint (last, 0, 10)
for decreasing count : 10 .. 0
delay (1000)
cls
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
put "Your quiz will begin in 10 seconds"
put count
end for
end if
end QuizSelect
%Quiz Selection End
procedure Instructions %Instruction Page Start
cls
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
put "Instructions Go Here"
Pic.ScreenLoad ("Back.bmp", 690, - 150, picMerge)
loop
Mouse.Where (x, y, button )
if x >= 810 and x <= 1000 and y >= 2 and y <= 80 and button = 1 then
Index
exit when x >= 810 and x <= 1000 and y >= 2 and y <= 80 and button = 1
end if
end loop
end Instructions
%Instructions Page End
procedure Lessons %Lessons Page Start
cls
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
put "Lessons Go Here"
Pic.ScreenLoad ("Back.bmp", 690, - 150, picMerge)
loop
Mouse.Where (x, y, button )
if x >= 810 and x <= 1000 and y >= 2 and y <= 80 and button = 1 then
Index
exit when x >= 810 and x <= 1000 and y >= 2 and y <= 80 and button = 1
end if
end loop
end Lessons
%Lessons Page End
procedure Credits %Credits Page Start
cls
%Background Set Up Start
locate (11, 1)
Pic.ScreenLoad ("matrix.bmp", 0, 0, picCopy)
drawfillbox (0, 300, maxx, 500, black)
%Background Set Up End
put "Credits Go Here"
Pic.ScreenLoad ("Back.bmp", 690, - 150, picMerge)
loop
Mouse.Where (x, y, button )
if x >= 810 and x <= 1000 and y >= 2 and y <= 80 and button = 1 then
Index
exit when x >= 810 and x <= 1000 and y >= 2 and y <= 80 and button = 1
end if
end loop
end Credits
%Credits Page End
%%%%%%%%%%%%%%%%%%%%%%%
%%%%%End Procedures%%%%
%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%Game Start%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%
StartProgram
loop
Index
case choice of
label "credits" :
Credits
label "instructions" :
Instructions
label "lessons" :
Lessons
label "quizselect" :
QuizSelect
end case
end loop
|
Ok Here is the entire code, There are some extra variables because i am planning on adding more things, and there also 2 empty Quiz areas. |
|
|
|
|
|
Clayton
|
Posted: Sun Dec 21, 2008 11:34 am Post subject: RE:Button Errors |
|
|
See in the loop where you have 1.5 seconds worth of delay? That's your problem. The time that you actually have to push that button between each of those 1.5 second periods is miniscule. You're very lucky to ever get a press in at all >.> |
|
|
|
|
|
Shockdot
|
Posted: Sun Dec 21, 2008 11:41 am Post subject: Re: Button Errors |
|
|
do you mean the delay (100) x15 ?
Even without those it still does the same thing
//////////////////Edit///////////////////////
Hmmmm i tryed that before and it didn't work but i just tryed it now and it worked but, i think there is a problem with my Credits procedure because it really gets bugged when you click it somtimes... Somtimes it does nothing other then cls the page back to the Index Procedure then you cant click any buttons until you re click Credits...
Also do you know of a way for me to include the code that gives 1.5 second dleay time without making the game mess up
//////////////// 2nd Edit///////////////////////
Ah nvm that was one stupid bug... See you were right about the 1.5 second delay thing but under that there was another error with the Credits Back Button... See they were nearly in the same place so as soon as you clicked the Credits button it would hit the Back button on the Credits Page, bringing it back to the Index page... Lol.
But i am still wondering if there is a way to include the Color Changeing Font.Draw with a delay, without messing anything up...
Also wondering if there is a Font list for turing somewhere. |
|
|
|
|
|
|
|