sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Array woes

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 73 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      Cheez
      last edited by

      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
      
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        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
        

        TIG

        1 Reply Last reply Reply Quote 0
        • C Offline
          Cheez
          last edited by

          Thanks works like a charm.

          I take it you added the @pts[0] to the test because @pts[] is not initialized with anything?

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            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...

            TIG

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement