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

Username:   Password: 
 RegisterRegister   
 Flashing Colours! Star and Stop.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
vdemons




PostPosted: 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>

Turing:


%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")

colourback(black)cls
       
procedure flash

    var message:string
    var hue:int:=1
    var font2:int
    font2 := Font.New("Times New Roman:50")
    colourback(green)cls

    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, 320, 238, font2, c)
            delay (200)
            var quitBtn : int := GUI.CreateButton (35, 5, 0, "Quit", GUI.Quit)
        end for
    end loop   

end flash

var b : int := GUI.CreateButton (300, 250, 0, "Start Program", flash)

loop
    exit when GUI.ProcessEvent
end loop

Window.Close (winID)




Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: Sat Apr 30, 2011 11:45 am   Post subject: RE:Flashing Colours! Star and Stop.

then what should i do to fix it
vdemons




PostPosted: 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.
vdemons




PostPosted: 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.
vdemons




PostPosted: 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)
Tony




PostPosted: Sat Apr 30, 2011 1:07 pm   Post subject: RE:Flashing Colours! Star and Stop.

You have an infinite loop.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: Sat Apr 30, 2011 1:20 pm   Post subject: RE:Flashing Colours! Star and Stop.

is there anyway to exit an infinite loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: 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
vdemons




PostPosted: 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
vdemons




PostPosted: Sat Apr 30, 2011 4:10 pm   Post subject: RE:Flashing Colours! Star and Stop.

here is an example!
vdemons




PostPosted: 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)
Tony




PostPosted: 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?
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  [ 14 Posts ]
Jump to:   


Style:  
Search: