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...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement