Expression has no scope

Monkey Forums/Monkey Programming/Expression has no scope

Nobuyuki(Posted 2012) [#1]
argh! This error is frustrating. I really don't know what I'm doing wrong here, but if I had to guess, it may have something to do with the arguments given in this constructor.

What I have here is the constructor for a Polygon class which takes 2 arguments; an array of Point (another class not listed here which is simply an x and y value), and a Vec2 value (from my 2d vector class). It is then supposed to take the point array and populate a List of Lines (yet another class not listed here that's been tested extensively and works, like the other classes), but the problem is that this code won't compile.

Trans gives me the error "Expression has no scope". I have no idea what this could possibly mean, since the compiler should know that it's supposed to be adding to the instance variable when (and only when) the argument points[] given has a valid length.

Could anyone help me figure out what I'm doing wrong here? Or, if not, at the very least explain to me what the error message is trying to tell me.

What follows is the code for the class
[monkeycode]Class Polygon 'Super polygon class for all things, including fields, bounds, etc.
Field Sides:=New List <Line>
Field dir:Vec2 = New Vec2 'Force field's force vector

Method New(points:Point[], direction:Vec2=New Vec2(0,1))
Self.dir = direction
If points.Length > 2 Then
For Local i:Int = 0 to points.Length -1
If i = 0 Then 'connect first and last point
Self.Sides.AddLast( New Line(points[0].x, points[0].y, points[points.Length-1].x, points[points.Length-1.y]))
Else
Self.Sides.AddLast( New Line(points[i].x, points[i].y, points[i-1].x, points[i-1.y]))
End If
Next
End If
End Method

End Class[/monkeycode]

the error occurs on the line that begins with "Self.Sides.AddLast("...


EDIT: Solved. there is a bracket typo where attempting to retrieve the member "y" from points in two of these lines. Can you spot it? The error thrown by Trans wasn't particularly helpful at helping me find it, but thanks to some friends who proofread the code, I was able to fix the problem.


Shinkiro1(Posted 2012) [#2]
Just a guess, but I think you can't create a new Vec2 as a default argument. The argument has to be known at compile time.


Samah(Posted 2012) [#3]
[monkeycode]points[i-1.y][/monkeycode]


Nobuyuki(Posted 2012) [#4]
Samah: You got it. It should be [monkeycode]points[i-1].y[/monkeycode]
and the equivalent for the other line, too.