Making a reset button work proplerly
Author |
Message |
Bobby321
|
Posted: Tue Jan 17, 2012 1:09 pm Post subject: Making a reset button work proplerly |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
Making a thermometer that changes temperature from Fahrenheit to Celsius and repeats.
What is the problem you are having?
The program repeats by clicking the orange button and most of the time it works but sometimes it takes many clicks to reset it. I need help to make it repeat with only 1 click every time.
Describe what you have tried to solve this problem
Try making a GUI button, but still no help.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
procedure drawrectangle
%screen formatting
setscreen ("graphics:800;400")
%orange button
var number : int
var rangeX, rangeY, button : int
cls
drawfillbox (200, 50, 250, 100, 42)
%keyboard input
put "Enter your temperature in farenheit from -4 to 68"
get number
put "Your temperature in celcius is:", (5 / 9) * (number - 32);
put "Click on the orange box to repeat"
%Mouse input
loop
mousewhere (rangeX, rangeY, button )
if (rangeX >= 200 and rangeX <= 250) and (rangeY >= 50 and rangeY <= 100) and button = 1 then
drawrectangle
else
end if
%Red box
drawbox (20, 40, 70, 100, 12)
drawbox (20, 100, 70, 160, 12)
drawbox (20, 160, 70, 220, 12)
drawbox (20, 220, 70, 280, 12)
%Yellow box
drawbox (70, 40, 120, 100, 43)
%Blue box
drawbox (120, 40, 170, 100, 54)
drawbox (120, 100, 170, 160, 54)
drawbox (120, 160, 170, 220, 54)
drawbox (120, 220, 170, 280, 54)
Text.Locate (1, 5)
for x : 50 .. 100
if number = 41 then
drawfillbox(20, 40, 70, 0+x, 12)
delay(10)
end if
if number = 35 then
drawfillbox (120, 40, 170, 0 + x, 54)
delay (10)
end if
end for
end loop
end drawrectangle
drawrectangle
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
mirhagk
|
Posted: Tue Jan 17, 2012 1:16 pm Post subject: RE:Making a reset button work proplerly |
|
|
well what you need to do is restructure your program.remove the loop from inside the function, as well as the mouse detection code, and put it outside. That way it gets drawn once, and then constantly checks if you press the button, and if so it calls the function again. |
|
|
|
|
|
|
|