
-----------------------------------
talyboy
Sun Jun 08, 2008 4:39 pm

URGENT!!!!! Creating a stoplight
-----------------------------------
Is it possible to make it so that when the program is executed, it first displays one light, lets say for 5 seconds, then a second light for another 5 seconds and then finally a third light (lights here being drawfillovals)?

-----------------------------------
Tony
Sun Jun 08, 2008 5:17 pm

RE:URGENT!!!!! Creating a stoplight
-----------------------------------
Yes, that is possible.

-----------------------------------
talyboy
Sun Jun 08, 2008 5:18 pm

Re: URGENT!!!!! Creating a stoplight
-----------------------------------
how?

-----------------------------------
syntax_error
Sun Jun 08, 2008 5:21 pm

RE:URGENT!!!!! Creating a stoplight
-----------------------------------
draw the stoplight
then in turing there is a magical thing called delay [for more information on this do use F10]
you make use that to pause the programing in changing the colours of the lights. 
That is how.

-----------------------------------
talyboy
Sun Jun 08, 2008 5:32 pm

Re: URGENT!!!!! Creating a stoplight
-----------------------------------
okay i'm not retarded. I now how to use delay. I would use it if it worked. THe problem is that the stoplight appears when i'm exiting a loop. When i use delay, the entire stoplight appears late, instead of just delaying one of the lights.

-----------------------------------
syntax_error
Sun Jun 08, 2008 5:39 pm

RE:URGENT!!!!! Creating a stoplight
-----------------------------------
I never intend the word, "retarded" for you, nor did I use it. 

As to your problem, use delay between each of the draw-ing of the lights, so you do something such as this :


proc redLight ()
proc yellowLight ()
proc greenLight()

/* draw the box of the lights here*/

loop
redLight()
delay (5000)

yellowLight()
delay (5000)

greenLight()
delay (5000)

end loop



EDIT: just to add, delay always works, it is not the function of that method, the problem is in the way you use it.

-----------------------------------
talyboy
Sun Jun 08, 2008 5:57 pm

Re: URGENT!!!!! Creating a stoplight
-----------------------------------
okay, this works perfectly outside of my code, but inside my code it messes up entirely. 

        
    var speed : int := 80
    var horizontalLocation : int := 0
    var key : string (1)
    var delaySpeed : int := 0
    var counter : int := 0

    drawfillbox (0, 0, 704, 500, 26) %The road
    drawfillbox (0, 500, 704, 704, 11) %The sky
    drawfillarc (352, 0, 75, 75, 0, 180, 2) %Original speedometer
    loop
        var startPointX : int := 30
        var startPointY : int := 490
        var endPointX : int := 50
        var endPointY : int := 430
        var colourStopLight : int



        drawfillbox (0, 0, 500, 500, 26) %Redraws the road to erase left over streaks
        locate (43, 45)
        put speed .. %original drawing of speed

        loop
            %Gets keyboard input
            getch (key)

            %Measures speed (up and down arrows)
            if key = chr (200) and speed < 80 then %Up arrow key
                speed := speed + 1
                delay (0) %Acceleration speed. delay (0) means 0 - 80 km/h in 3 seconds.
            elsif key = chr (208) and speed > 0 then %Down arrow key
                speed := speed - 1
            end if
            drawfillarc (352, 0, 75, 75, 0, 180, 2) %Drawing the speedometer
            locate (43, 45)
            put speed .. %Changing speed

            %Measures horizontal placement on screen (left and right arrows)
            if key = chr (205) and horizontalLocation < 200 then %Right arrow key
                horizontalLocation := horizontalLocation + 10
            elsif key = chr (203) and horizontalLocation > 0 then %left arrow key
                horizontalLocation := horizontalLocation - 10
            end if
            for x : 0 .. 1
                if speed > 0 then
/*section cut out*/
                    if speed = 80 and startPointY > 0 then
                        startPointY := startPointY - 1
                        endPointY := endPointY - 1
                        delaySpeed := 0
                    end if


                    drawfillbox (startPointX, startPointY + 400 + 1, endPointX, endPointY + 400 - 1, 26)
                    drawfillbox (startPointX, startPointY + 400, endPointX, endPointY + 400, 14)

                    drawfillbox (startPointX, startPointY + 300 + 1, endPointX, endPointY + 300 - 1, 26)
                    drawfillbox (startPointX, startPointY + 300, endPointX, endPointY + 300, 14)

                    drawfillbox (startPointX, startPointY + 200 + 1, endPointX, endPointY + 200 - 1, 26)
                    drawfillbox (startPointX, startPointY + 200, endPointX, endPointY + 200, 14)

                    drawfillbox (startPointX, startPointY + 100 + 1, endPointX, endPointY + 100 - 1, 26)
                    drawfillbox (startPointX, startPointY + 100, endPointX, endPointY + 100, 14)

                    drawfillbox (startPointX, startPointY + 1, endPointX, endPointY - 1, 26)
                    drawfillbox (startPointX, startPointY, endPointX, endPointY, 14)

                    drawfillbox (startPointX, startPointY - 100 + 1, endPointX, endPointY - 100 - 1, 26)
                    drawfillbox (startPointX, startPointY - 100, endPointX, endPointY - 100, 14)

                    drawfillbox (startPointX, startPointY - 200 + 1, endPointX, endPointY - 200 - 1, 26)
                    drawfillbox (startPointX, startPointY - 200, endPointX, endPointY - 200, 14)

                    drawfillbox (startPointX, startPointY - 300 + 1, endPointX, endPointY - 300 - 1, 26)
                    drawfillbox (startPointX, startPointY - 300, endPointX, endPointY - 300, 14)

                    drawfillbox (startPointX, startPointY - 400 + 1, endPointX, endPointY - 400 - 1, 26)
                    drawfillbox (startPointX, startPointY - 400, endPointX, endPointY - 400, 14)

                    delay (delaySpeed)

                    drawfillbox (0, 500, 704, 704, 11)     %The sky
                    View.Update
                else
                    drawfillbox (startPointX, startPointY, endPointX, endPointY, 14)
                end if
                exit when startPointY = 0
            end for
            exit when startPointY = 0
        end loop
        counter := counter + 1
        locate (1, 1)
        put counter

        if counter = 1 then %Stop light
            for x : 1 .. 20
                drawarc (550 + x, 335 + x, 100, 100, 0, 90, 14) %Stop light arc
            end for

            drawfillbox (650, 30, 670, 355, 14) %Stop light pole
            drawfillbox (530, 400, 580, 490, 16) %Stop light rectangle
            loop
                colourStopLight := 44
                drawfilloval (555, 445, 10, 10, colourStopLight) %Stop light yellow
                delay (5000)
                
                colourStopLight := 12
                drawfilloval (555, 470, 10, 10, colourStopLight) %Stop light red
                delay (5000)

                colourStopLight := 2
                drawfilloval (555, 420, 10, 10, colourStopLight)     %Stop light green
            end loop
        end if
    end loop
end userInput
userInput



When its inside all this code, for some reason it doesn't work properly! Can you PLEASE help me figure out why?

-----------------------------------
Insectoid
Sun Jun 08, 2008 7:10 pm

RE:URGENT!!!!! Creating a stoplight
-----------------------------------
Could you post the ENTIRE procecdure (and any additional things we need to make it exactly the same as yours)?

-----------------------------------
Tony
Sun Jun 08, 2008 7:26 pm

RE:URGENT!!!!! Creating a stoplight
-----------------------------------
Perhaps as an attachment. This is getting quite lengthy as it is.
