HELP: i need to programm a traffic light an it doesn't work

Hello Everabody,

i need this Programm for my exam on wednesday and i am getting out of my
mind…

i need to write a programm that changes traffic lights for the
pedastrians after pushing the “Walk” button an at the same time the
right Light for the cars, so that they would stop and go at the right
moment.

i would like to do it with a procedure for time. I tried it out on Ruby
and it worked, tried it out as a simple singular programm. it worked but
not as it should. as soon as i ad the procedure to my programm my Shoes
screen turnes black an the colors appear at the same time and not
differentiated as they should.

the same problem with my traffic light programm: as soon as i ad the
procedure for time my screen turnes black, there is no squere for the
traffic ligts and there is no color changing in it.

can anybody help me?!!

On Dec 10, 2011, at 3:19 PM, Akvile K. wrote:

i would like to do it with a procedure for time. I tried it out on Ruby

Attachments:
http://www.ruby-forum.com/attachment/6828/Traffic1.jpg
http://www.ruby-forum.com/attachment/6829/Traffic2.jpg
http://www.ruby-forum.com/attachment/6830/Test.jpg
http://www.ruby-forum.com/attachment/6831/shoes_Test.jpg
http://www.ruby-forum.com/attachment/6832/Shoes_Traffic.jpg

And how do you suppose people are going to help you? By manually
retyping small pieces of your overall code presented in some obscure
images? Why not to include the relevant amount of code in text format
attached to your post?

Wouldn’t you get frustrated yourself seeing such posts from other
people? Normally, if you really need some help try to make it as easy as
possible for a potential helper to access your code. Otherwise you are
out of luck.

Regards,
Gennady.

one should not post long source codes in text, but here you go:

Shoes.app :height=> 500, :width=> 500 do
background white

#fußgägerampel

fill gainsboro
rect 10,50,90,130
fill red
a1=oval :top=> 60, :left=> 30, :radius=> 25
fill black
a2=oval :top=> 120, :left=> 30, :radius=> 25

#autoampel

fill gainsboro
rect 210,45,150,300
fill black
b1=oval :top=> 50, :left=> 245, :radius=> 40
fill black
b2=oval :top=> 150, :left=> 245, :radius=> 40
fill green
b3=oval :top=> 250, :left=> 245, :radius=> 40

def alle (dauer)
tn=Time.now.to_i #Prozedur alle
te=tn+dauer
while tn<te do
tn=Time.now.to_i
end
end

stack :margin=> 30, :top=> 150 do
button “Walk” do

#fußgängerampel

alle 5 do
fill red
a1=oval :top=> 60, :left=> 30, :radius=> 25
fill black
a2=oval :top=> 120, :left=> 30, :radius=> 25
end
#Autoampel

alle 5 do
fill black
b1=oval :top=> 50, :left=> 245, :radius=> 40
fill black
b2=oval :top=> 150, :left=> 245, :radius=> 40
fill green
b3=oval :top=> 250, :left=> 245, :radius=> 40
end

end

end

end

and the Test programm:

def pause (dauer)
tn = Time.now.to_i
te = tn+dauer
while tn<te do
tn = Time.now.to_i
end
end

Shoes.app do
fill white
rect 10,50,90,130

stack do

button “P” do

pause (2)

fill red
oval :top=> 50, :left=> 150, :radius=> 25

pause (15)

fill green
oval :top=> 150, :left=> 150, :radius=> 25
end
end
end

Hi Akvile and folks,

as soon as i ad the procedure to my programm my Shoes screen
turnes black an the colors appear at the same time and not
differentiated as they should.
Umm,…
I tried out the code you posted with my Shoes 3 (0.r1514) on Windows 7.
But the Shoes screen didn’t turn to black…
What platform and Shoes version are you using?
You might have found a bug…

Anyway, try out the following.
I think it’s better to use timer() method.

Shoes.app do
button “P” do
timer 2 do
oval :top=> 50, :left=> 150, :radius=> 25, :fill => red
end
timer 15 do
oval :top=> 150, :left=> 150, :radius=> 25, :fill => green
end
end
end

And one more shot. :wink:
If you want to change the color of the same light,
try out the following.

Shoes.app do
nostroke
light1 = oval :top=> 50, :left=> 150, :radius=> 25
light2 = oval :top=> 150, :left=> 150, :radius=> 25
button “P” do
timer 2 do
light1.fill = red
end
timer 15 do
light2.fill = green
end
end
end

Cheers and have fun Shoes,
ashbb

On 12/10/2011 6:49 PM, Akvile K. wrote:

one should not post long source codes in text, but here you go
use www.pastebin.com

or one of the other alternatives
http://en.wikipedia.org/wiki/Comparison_of_pastebins