EDIT: Issue resolved in the 2 posts below this. Skip this post unless you're really interested in boring yourself to death.
OK, its morning and I'm back!
@line_positions is an array of points on the x axis. Each point acts as the base starting point for each vertical grid line. So first the method checks to see if @line_positions has been populated yet. If it has, then it takes each value from that array and calls it p1 and then adds an amount to the y of 100 and calls that p1, then draws the line from p1 (the base) to p2, the top of the vertical line.
The 5.times do portion is drawing the horizontal lines by taking the first and last points on the horizontal boundaries. Then adds 20 to each and draws a line. Does that 5 times, and those are the horizontal grid lines.
To explain better, @line_positions is defined once when the user hits enter. Its values do not change at all normally. To test this, I added a puts @line_positions[0] statement in my onKeyUp method. So everytime I press a key, it puts the first @line_positions position. And sure enough, when I disable the draw method, that value stays the same.
But once I enable the draw method, that value changes everytime the screen is redrawn. So it appears that somehow something that I have in the draw method is changing the @line_positions, not just getting values from it.
More specifically, when I comment out the 5.times portion (which is the part that draws the horizontal grids), then the method works as expected and does not change my @line_positions values. So I think it is something with how I have that written, but I can't see anything in there that should affect the @line_positions values.
def draw( view )
if !@line_positions.empty?
@line_positions.each do |e|
p1 = e
p2 = p1.clone
p2[1] += 100
view.draw GL_LINES, p1, p2
end
np1 = @line_positions[0]
np2 = @line_positions.last
puts "from draw " + @line_positions[0].y.to_f.to_s
#5.times do
# np1[1] = np1[1] + 20
# np2[1] = np2[1] + 20
# view.draw GL_LINES, np1, np2
#end
end
end
All I can think is that is it possible that it thinks that since np1 points to @line_positions[0] when I change np1 it thinks I want the original @line_positions[0] value changed too and somehow sends the change back to that array? I'm a bit stumped with this one....
Chris