Array woes
-
Hello,
I have the following methods in a class, the idea being that the user is to click various points on a model and the tool knows the user selection is finished when a click matches the first click, so if they were tracing a square the 5th click will be the same as the first and trigger the puts(). However the puts() is always triggered by the second click even when it is definately not clicked in the same place.
Any advice much appreciated.def initialize @ip = nil @pts = [] end def activate @ip = Sketchup;;InputPoint.new end def onLButtonUp(flags,x,y,view) @ip.pick(view,x,y) if(@ip == @pts[0]) puts("Start Point Clicked") else @pts << @ip end end
-
Try saving the input point as a proper point3d object, using '.position'
def onLButtonUp(flags,x,y,view) @ip.pick(view,x,y) if @pts[0] && @ip.position==@pts[0] puts("Start Point Clicked") else @pts << @ip.position end end
-
-
Yes, it'd return an error or if @ip1 is nil then it might be seen as equal to an empty @pts[] ?
If you are testing something that might be nil it's a good idea to check it exists first...
Advertisement