Computer Science Canada Flashing Colours! Star and Stop. |
Author: | vdemons [ Fri Apr 29, 2011 4:25 pm ] | ||
Post subject: | Flashing Colours! Star and Stop. | ||
What is it you are trying to achieve? I am trying to make my code flash, having simple start and stop buttons. What is the problem you are having? I am able to start it, but have no idea on how to stop it, i made a quit button but it doesn't do anything. Describe what you have tried to solve this problem i used all sorts of close windows or exit commands but they don't work. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <Answer Here> |
Author: | Tony [ Fri Apr 29, 2011 4:31 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
Your code never gets to GUI.ProcessEvent, and without it, buttons are not processed. Also, you create 5 new buttons every second. |
Author: | vdemons [ Sat Apr 30, 2011 11:45 am ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
then what should i do to fix it |
Author: | vdemons [ Sat Apr 30, 2011 11:51 am ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
can you please give me some help on fixing this, my teacher has high standards. |
Author: | vdemons [ Sat Apr 30, 2011 12:00 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
is it possible to make a procedure inside the loop that can only be activated when the quit button is pressed and will exit on a command that is already true. Such as an "exit when" statement for loops. |
Author: | vdemons [ Sat Apr 30, 2011 12:18 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
Here i revamped it. but it still can't exit! %Vishnu Kumar %April 29 import GUI var winID := Window.Open ("graphics:700;500") View.Set ("graphics:700;500,position:top;right,nobuttonbar") View.Set ("title: The Flash") var message:string var hue:int:=1 var font2:int font2 := Font.New("Times New Roman:50") procedure flash var intfont : int intfont := Font.New("Times New Roman:18") Font.Draw("Please remember to put your message in quotations(\" \")", 150, 10, intfont, black) put "Please enter your message: ".. get message loop for c: 1..15 colour(c) Font.Draw (message, 220, 238, font2, delay (200) end for end loop end flash var quitBtn : int := GUI.CreateButton (35, 5, 0, "Quit", GUI.Quit) var b : int := GUI.CreateButton (35, 400, 0, "Start Program", flash) loop exit when GUI.ProcessEvent end loop Window.Close (winID) |
Author: | Tony [ Sat Apr 30, 2011 1:07 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
You have an infinite loop. |
Author: | vdemons [ Sat Apr 30, 2011 1:20 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
is there anyway to exit an infinite loop |
Author: | Tony [ Sat Apr 30, 2011 1:29 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
If you want to do it with GUI buttons, you would need to use GUI.ProcessEvent in every loop (or to have just a single loop). FYI, GUI would not work during delays. |
Author: | vdemons [ Sat Apr 30, 2011 3:48 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
is it possible to put a procedure within a procedure |
Author: | vdemons [ Sat Apr 30, 2011 3:58 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
is there any way to exit my infinite loop even if its not with GUI buttons like entering a key ie. spacebar to exit. because i have no idea what to do |
Author: | vdemons [ Sat Apr 30, 2011 4:10 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
here is an example! |
Author: | vdemons [ Sat Apr 30, 2011 4:11 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
import GUI var winID := Window.Open ("graphics:700;500") View.Set ("graphics:700;500,position:top;right,nobuttonbar") View.Set ("title: The Flash") var message:string var hue:int:=1 var font2:int font2 := Font.New("Times New Roman:50") var chars : array char of boolean procedure flash var intfont : int intfont := Font.New("Times New Roman:18") Font.Draw("Please remember to put your message in quotations(\" \")", 150, 10, intfont, black) put "Please enter your message: ".. get message loop for c: 1..15 colour(c) Font.Draw (message, 220, 238, font2, c) delay (200) Input.KeyDown (chars) if chars ('t') then exit end if end for end loop end flash var quitBtn : int := GUI.CreateButton (35, 5, 0, "Quit", GUI.Quit) var b : int := GUI.CreateButton (35, 400, 0, "Start Program", flash) loop exit when GUI.ProcessEvent end loop Window.Close (winID) |
Author: | Tony [ Sat Apr 30, 2011 7:15 pm ] |
Post subject: | RE:Flashing Colours! Star and Stop. |
Yes, something like this. Would exit terminate the for-loop first, or the outer loop? |