Button help please!
Author |
Message |
Kanaki
|
Posted: Mon Jan 25, 2010 8:43 pm Post subject: Button help please! |
|
|
What is it you are trying to achieve?
I'm trying to finish my project which is due tomorrow. It is a program that can disarm or arm(with a help button) an alarm system.
What is the problem you are having?
The buttons are not working when I go and press it and I don't even know if the program is correct.
Describe what you have tried to solve this problem
I tried the positioning of the loop and it still did not work, it did work once but then after it didn't work at all.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here's the code. And I have the pictures if you want it.
Turing: |
import GUI in "%oot/lib/GUI"
View.Set ("graphics:800,600")
var p : int := Pic.FileNew("enterpassword.jpg")
Pic.Draw (p, 0, 0, 0)
%The button's location.
const armX1 := 521
const armY1 := 4
const armX2 := 648
const armY2 := 194
const disarmX1 := 148
const disarmY1 := 11
const disarmX2 := 297
const disarmY2 := 190
const helpX1 := 681
const helpY1 := 290
const helpX2 := 774
const helpY2 := 392
var check : boolean := false %checks if alarm is secure or not.
var value : int
var x,y,button : int
loop
const password:= 1
var typed: int
var font:= Font.New("Times:30")
get typed
%So it doesn't lag or doesn't go over what is pressed.
GUI.Refresh
var a : int := Pic.FileNew ("FSE menu copy.jpg")
Pic.Draw (a, 0, 0, 0)
drawbox(armX1,armY1,armX2,armY2, black)
drawbox(disarmX1,disarmY1,disarmX2,disarmY2, black)
drawbox(helpX1,helpY1,helpX2,helpY2, black)
if typed=password then
mousewhere (x, y, button )
%Once the armed button is pressed, the alarm will set off if the door is opened.
if armX1 <= x and x <= armX2 and armY1 <= y and y <= armY2 and button = 1 /*or (parallelget div 64)mod 2 = 0*/ then
locatexy(300, 528)
colour(green)
put "Secure..."
parallelput(1)
check := true
elsif helpX1 <= x and x <= helpX2 and helpY1 <= y and y <= helpY2 and button = 1 then
locatexy(300, 528)
colour(green)
put "Hint: #"
%If the disarmed button is pressed then it should turn off
elsif disarmX1 <= x and x <= disarmX2 and disarmY1 <= y and y <= disarmY2 and button = 1 then
locatexy(300, 528)
colour(green)
put "Disarmed"
parallelput(0)
check := false
end if
%If the door is opened depending on if it is disarmed
%or not then you'll be an intruder or not.
if check then
value := parallelget
if (value div 64) mod 2 = 1 then
locatexy(300, 528)
colour (green)
put "No Intruders"
else
locatexy(300, 528)
colour (brightred)
put "INTRUDER ALERT"
parallelput(3)
end if
end if
else %this is when the password is not typed correctly
%then the alarm will set off.
Font.Draw("WRONG!", 300, 528,font, red)
parallelput(0)
end if
end loop
locatexy(300, 528)
put "Activating alarm."
parallelput(0)
delay(50)
parallelput(1)
|
Please specify what version of Turing you are using
Turing 4-1-1a
Description: |
|
Filesize: |
257.71 KB |
Viewed: |
58 Time(s) |
|
Description: |
|
Filesize: |
243.58 KB |
Viewed: |
53 Time(s) |
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
ProgrammingFun
|
Posted: Mon Jan 25, 2010 9:23 pm Post subject: Re: Button help please! |
|
|
You used mousewhere in this code.
Instead of this, you could use buttonwait in a loop as you buttons.
Turing: |
% example
var x, y, bnum, bud, num
% waiting for first input
loop
buttonwait (x,y,bnum,bud )
if x >= 5 and x <= 80 and y>= 20 and y <= 50 then
num = 1
exit
elsif % and so on
else
end if
end loop
% waiting for second input
loop
%same stuff
end loop
%and so on
|
You could also do this using procedures.
However, this may be too long and complicated if your project is due tmrw.
BTW, if you post multiple files, you might as well just upload a zip containing all of them.
|
|
|
|
|
|
|
|