Posted: Mon May 02, 2011 10:53 am Post subject: How To Make Loop on This Program
What is it you are trying to achieve?
I'm trying to make my flashing text loop.
What is the problem you are having?
I can't seem to make my text loop and whenever I do, my quit button doesn't work.
Describe what you have tried to solve this problem
I tried adding loop but whenever I do add it, it cancels out my quit button.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
import GUI
var winID := Window.Open ("graphics:500;500")
put "Enter your message here please: "..
var message:string
get message
put " "
put "You'll be able to quit once the program is done going through all possible colours in Turing"
var font1:int
font1 := Font.New ("times:50")
for integer:0..16
colour (integer)
Font.Draw (message, 200, 250, font1, integer)
delay (250)
end for
var quitBtn : int := GUI.CreateButton (250, 10, 0, "Quit", GUI.Quit)
loop
exit when GUI.ProcessEvent
end loop
Window.Close (winID)
Turing:
<Add your code here>
Please specify what version of Turing you are using
I'm using version 4.1.1
Sponsor Sponsor
munt4life
Posted: Mon May 02, 2011 5:48 pm Post subject: Re: How To Make Loop on This Program
put it inside the loop then.
Raknarg
Posted: Mon May 02, 2011 5:51 pm Post subject: RE:How To Make Loop on This Program
It's because of the amount of time you have to click the button. You have four windows of opportunity every second to click the button, each about a millisecond long.
Instead of a delay, I would use a counter that goes up to 250, then changes the colour and goes back down to zero. That way it'll always be checking the button. I just tried it, and it works.
darkage43
Posted: Mon May 02, 2011 7:13 pm Post subject: RE:How To Make Loop on This Program
So how would I use this counter? I can't find it on the turing reference.
Raknarg
Posted: Mon May 02, 2011 7:24 pm Post subject: RE:How To Make Loop on This Program
Use a variable and set it to int. Every time the loop passes, you add one to it.
You would set the counter up like so:
counter := counter + 1
if counter = 250 then
integer := integer + 1
counter := 0
end if
darkage43
Posted: Mon May 02, 2011 7:33 pm Post subject: RE:How To Make Loop on This Program
Like this?
import GUI
var winID := Window.Open ("graphics:500;500")
var counter: int:=0
put "Enter your message here please: "..
var message:string
get message
put " "
put "You'll be able to quit once the program is done going through all possible colours in Turing"
var font1:int
font1 := Font.New ("times:50")
for integer:0..255
colour (integer)
Font.Draw (message, 200, 250, font1, integer)
counter := counter + 1
if counter = 250 then
int := int + 1
counter := 0
end if
end for
var quitBtn : int := GUI.CreateButton (250, 10, 0, "Quit", GUI.Quit)
loop
exit when GUI.ProcessEvent
end loop
Window.Close (winID)
darkage43
Posted: Mon May 02, 2011 7:35 pm Post subject: RE:How To Make Loop on This Program
I really don't understand this.
Raknarg
Posted: Mon May 02, 2011 7:43 pm Post subject: RE:How To Make Loop on This Program
Explain to me exactly what you want it to do.
Sponsor Sponsor
darkage43
Posted: Mon May 02, 2011 7:47 pm Post subject: RE:How To Make Loop on This Program
Oh! I see, thanks a lot Raknarg, but how do I make the program cycle through a specific set of colours?
Raknarg
Posted: Mon May 02, 2011 7:52 pm Post subject: RE:How To Make Loop on This Program
Umm... Well, unless there's colors in order already, you'll just have to use a lot of ifs. Like if you wanted to have red, blue and yellow, you could do something like
However, colors 32 to 80 are pretty nice, I would just cycle through those.
Raknarg
Posted: Mon May 02, 2011 7:55 pm Post subject: RE:How To Make Loop on This Program
If that helped, there's always tipping with karma to show appreciation
darkage43
Posted: Mon May 02, 2011 7:57 pm Post subject: RE:How To Make Loop on This Program
So if I wanted colors from 1 to 16 I would put
for i :1..16
colour (integer)
Font.Draw (message, 350, 425, font1, integer)
counter += 1
if counter = 200 then
integer += 1
counter := 0
end if
end for
darkage43
Posted: Mon May 02, 2011 7:59 pm Post subject: RE:How To Make Loop on This Program
Actually never mind I got it to cycle through the colours that I want. One final question though. How do I slow down the cycling of the colours?
Raknarg
Posted: Mon May 02, 2011 8:01 pm Post subject: RE:How To Make Loop on This Program
Change the counter length, right? Thats the thing making the change.
darkage43
Posted: Mon May 02, 2011 8:11 pm Post subject: RE:How To Make Loop on This Program
Which ones the counter length? I tried changing all of the counters but they are still flashing too fast.