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

Username:   Password: 
 RegisterRegister   
 Traffic light program, animation speeding up for no reason!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Xiphos




PostPosted: Sat May 14, 2016 9:45 am   Post subject: Traffic light program, animation speeding up for no reason!

What is it you are trying to achieve?
I'm trying to make a traffic light program with 2 sets of lights that are tied to eachother, and two cars that stop at the intersection if the light for that lane is red.


What is the problem you are having?
It works fine for a few loops (car reaches the end and redraws at the beginning) but after a few loops the cars start to freak out; running red lights, speeding up, drawing weird shapes etc.


Describe what you have tried to solve this problem
I tried extending the range in which the cars will stop when they see a red light, and i tried resetting the speed variable at the end of the loop


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Here is a pastebin link to the full code: http://pastebin.com/fzdP0dTm


The code for just the car:
Turing:

 process Hcar ()  %The horizontal car
    loop
        drawfillbox ((xI - 10), yI, (xI2 - 4), yI2, grey) %Removes the previous drawn shape
        drawfillbox (xI, yI, xI2, yI2, blue)
        xI := xI + speed
        xI2 := xI2 + speed

        if xI2 <335 and xI2 >320  then  %When the car is near the end of the intersection
            if statusII = "red" or statusII = "yellow" then
                loop
                    delay (10)
                    drawHwalk
                    exit when statusII = "green" %exit when green
                end loop
            end if
        end if
        if xI2 >= 800 then
            drawfillbox (1, 355, 799, 395, grey)
            drawHwalk
            xI := 10
            xI2 := 85
            yI := 360
            yI2 := 390
            delay (50)

        end if


        %View.UpdateArea (0, 350, 800, 450)
        delay (50)
        %drawfillbox (1, 355, 799, 395, white) (OLD VERSION)
        drawHwalk
        speed:= 4
    end loop
end Hcar



Please specify what version of Turing you are using
4.1.1



Help is greatly appreciated!
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Sun May 15, 2016 5:41 pm   Post subject: Re: Traffic light program, animation speeding up for no reason!

You're using processes. That in and of itself is cause for concern. It would be best if you rewrote your program to avoid using processes (seriously).

I don't really know what is causing your problem, but you might want to check how many Hcar and Vcar processes you have running at any given time.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: