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

Username:   Password: 
 RegisterRegister   
 I've been using turing for 2 weeks.. I need 5 seconds !!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Soapies




PostPosted: Wed Jun 07, 2006 10:21 pm   Post subject: I've been using turing for 2 weeks.. I need 5 seconds !!

You guys probably have this code memorized so if you wouldn't mind helping me out here...

All I need to do is know how to make a clickable box that .. say.. turns a light red with one click, but then turns the light back to white with another click.

So far I have been able to make it work with two boxes.. One for ON the other for OFF.. but for my culminating activity .. (we're making a program that will add two binary numbers together then show the correct answer with LEDs on a circuit diagram connected through the parallel port).. and.. yeah I'm having a hard time getting a button that will turn on and off..

This is the best I can get (in it's most basic out-of-the-text format)

code:
procedure gui
    locatexy (110, 325)
    put "ON"
    locatexy (110, 200)
    put "OFF"
    locatexy (110, 75)
    put "EXIT"
    drawbox (50, 275, 175, 375, red)
    drawbox (50, 150, 175, 250, red)
    drawbox (50, 25, 175, 125, red)
    drawoval (450, 250, 25, 25, black)
end gui

var x, y, button : int
gui
loop
    mousewhere (x, y, button)
    if button = 1 and 50 <= x and x <= 175 and 275 <= y and y <= 375 then
        drawfill (450, 250, red, black)
    elsif button = 1 and 50 <= x and x <= 175 and 150 <= y and y <= 250 then
        drawfill (450, 250, white, black)
    end if
    exit when button = 1 and 50 <= x and x <= 175 and 25 <= y and y <= 125
end loop


Is there a way to turn the light on and off with only one button? My teacher tried looking, but he had a problem too..
Sponsor
Sponsor
Sponsor
sponsor
Soapies




PostPosted: Wed Jun 07, 2006 10:25 pm   Post subject: (No subject)

P.S.

If this helps at all, I'm using "const" and "drawbox (whateverinamedtheconst)" for my culminating.. I tried using a "loop" but my teacher says it has something to do with the boolean equation..

heh.
Guest




PostPosted: Wed Jun 07, 2006 10:38 pm   Post subject: (No subject)

If you know how to use boolean, make a boolean variable that returns true when it is first press, then returns false when pressed again, etc. I'll work on some code to help you right now..
Guest




PostPosted: Wed Jun 07, 2006 10:41 pm   Post subject: (No subject)

Try this:
code:

procedure gui
    locatexy (110, 325)
    put "ON"
    locatexy (110, 200)
    put "OFF"
    locatexy (110, 75)
    put "EXIT"
    drawbox (50, 275, 175, 375, red)
    drawbox (50, 150, 175, 250, red)
    drawbox (50, 25, 175, 125, red)
    drawoval (450, 250, 25, 25, black)
end gui

var x, y, button : int
var on : boolean := true
gui
loop
    mousewhere (x, y, button)
    if button = 1 and 50 <= x and x <= 175 and 275 <= y and y <= 375 then
        if on = true then
            drawfill (450, 250, red, black)
            on := false
        else
            drawfill (450, 250, white, black)
            on := true
        end if
    end if
    exit when button = 1 and 50 <= x and x <= 175 and 25 <= y and y <= 125
end loop


But you will have to figure out how to delay it if it clicks too fast...
TheOneTrueGod




PostPosted: Thu Jun 08, 2006 7:20 am   Post subject: (No subject)

vahnx, don't just give him code.

Soapies, all you have to do is have an "oldbutton" variable. Just before the mousewhere statement, set oldbutton to button. You'll get an error, but i'll leave it up to you to fix that Wink

then, the if statement should be
code:

if button = 1 and oldbutton = 0 then


good luck
Soapies




PostPosted: Thu Jun 08, 2006 3:41 pm   Post subject: (No subject)

Thanks guys! I left my disk at school (in the auditorium too! eeek), so I won't be able to put it in, but I deffinately will once I get the chance and I thank you a lot because I reeally couldn't figure it out.

and just for the record, I'm a girl Wink lol

Edit: I tried it and it works amazingly! I was able to put a delay in it and.. IT WORKS!!! Haha, I'm just really happy because it wasn't as hard as it seemed to be.

Thanks, both of you, for your help!
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 1  [ 6 Posts ]
Jump to:   


Style:  
Search: