A program error

hi, all! my compiler doesn’t like the “minus” in line 21, it’s like:

/home/cristi/NetBeansProjects/RubyApplication3/lib/helic.rb:21:
undefined method `-’ for “”:String (NoMethodError)

1 require “init.rb”
2
3 shots = 3
4 time = 1
5 speed = 0
6 x=y=1
7 while (shots!=0) do
8 #give entry data
9 puts “let’s fck da su**er!"
10 puts “give speed:”
11 speed = gets
12 puts “give angle:”
13 angle = gets
14 #processing entry data
15 angle=(Math::PI)/180
angle.to_f
16 xspeed=speedMath.cos(angle)
17 yspeed=speed
Math.sin(angle)
18 #trajectory’s loop
19 while (y>0) do
20 x=xspeedtime
21 y=yspeed
time-4.9*time**2
22 time+=0.01
23
24 #puts “x=”+x.to_i.to_s+” y="+y.to_i.to_s
25 screen.fill_rect 0, 0, 640, 480, BGCOLOR
26 screen.draw_circle x, y, 5, SHELLCOLOR
27 screen.flip
28
29 end
30 shots-=1
31 puts “shots remaining”+ shots.to_s
32 end

help, please. thanks!

it appears that yspeed is “”, which implies speed from gets is not what
you expect it to be. puts speed after you gets it and see.

Zhao Lu wrote:

it appears that yspeed is “”, which implies speed from gets is not what
you expect it to be. puts speed after you gets it and see.

The answer is

speed = gets.to_s

puts speed gave integer, but puts xspeed(and yspeed too) gave “”. You
were about right. I fell so stupid…

Thanks!

speed = gets.to_s

shit, I had to write

speed = gets.to_f

sorry

Hi,

Am Mittwoch, 16. Dez 2009, 16:38:07 +0900 schrieb Teodor C.:

hi, all! my compiler doesn’t like the “minus” in line 21, it’s like:

/home/cristi/NetBeansProjects/RubyApplication3/lib/helic.rb:21:
undefined method `-’ for “”:String (NoMethodError)

[…]
20 x=xspeedtime
21 y=yspeed
time-4.9*time**2
[…]

Put something like this before line 21 and the cause of the error
is obvious:

puts [ xspeed, yspeed, time].inspect

Bertram

Try to use
speed = gets.to_i at line 11 and
angle = gets.to_i at line 13 to resolve this.

Regards,
Raghav