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

Username:   Password: 
 RegisterRegister   
 Can't click GUI Buttons if a loop is running - Traffic Light System
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ShifatT




PostPosted: Thu Feb 28, 2013 5:37 pm   Post subject: Can't click GUI Buttons if a loop is running - Traffic Light System

What I am doing:
I am trying to make a Traffic Light System for class.

Problem :
When a loop is running, I cannot click any buttons until the loop ends.
Eg: If I start Auto-Mode, I cannot click any buttons until the for-loop ends.

What I did:
Remove the loop - Which defeated the purpose of some of the features of the program

Code: Attatched

Turing Version :
4.1.2, 4.0.5 at School.[/u]



TrafficLights.t
 Description:
Code

Download
 Filename:  TrafficLights.t
 Filesize:  11.25 KB
 Downloaded:  90 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Feb 28, 2013 6:35 pm   Post subject: RE:Can\'t click GUI Buttons if a loop is running - Traffic Light System

programs are linear and do one thing at a time. If the program is busy spending time inside of for-loop, it will not get to the code that handles the buttons (or anything else) for a while.

The solution -- don't block on long running loops.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ShifatT




PostPosted: Thu Feb 28, 2013 7:58 pm   Post subject: Re: RE:Can\'t click GUI Buttons if a loop is running - Traffic Light System

Tony @ Thu Feb 28, 2013 6:35 pm wrote:
programs are linear and do one thing at a time. If the program is busy spending time inside of for-loop, it will not get to the code that handles the buttons (or anything else) for a while.

The solution -- don't block on long running loops.


So I just leave it as it is?
Tony




PostPosted: Thu Feb 28, 2013 9:22 pm   Post subject: RE:Can\'t click GUI Buttons if a loop is running - Traffic Light System

If you understand what's going on and that is acceptable to you.

Basically in a scenario such as
code:

loop
  do_a
end loop

loop
  do_b
end loop


B has to wait for A to completely finish. An alternative is to design your code to be along the lines of
code:

loop
  do_a
  do_b
end loop


This way A and B alternate taking steps, and both get to make some progress, without waiting for the other for too long.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: