sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Sharing variables between functions

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 177 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.
    • K Offline
      kybasche
      last edited by

      Hey all.

      One day, I'll get good enough at this to offer help instead of only asking question.
      But for now:

      I would like to be able to use variables from one function inside a different function. Please forgive my poor scripting - but as an example...

      module Plugin
      
      unless file_loaded?("program.rb")
      mymenu = UI.menu('Plugins').add_submenu('test')
      mymenu.add_item('Test Program') {self.Box}
      mymenu.add_item('Test Program 2') {self.Circle}
      file_loaded("program.rb")
      end #unless
      
      def self.Box()
      a = 5
      b = 6
      c = a * b
      end #Box
      
      def self.Circle()
      d = 12
      e = d * a ##this won't work of course, because (a) is not defined within this function... how do you pull the value of (a) from Box?
      end #failCircle
      
      end #module
      

      Thanks much!

      Derek

      1 Reply Last reply Reply Quote 0
      • ChiefwoodworkerC Offline
        Chiefwoodworker
        last edited by

        Hi Derek,

        Make variable a a class instance variable e.g.@a.

        def self.Box()
        @a = 5
        b = 6
        c = @a * b
        end #Box

        def self.Circle()
        d = 12
        e = d * @a

        end #module

        Joe....
        http://www.srww.com

        1 Reply Last reply Reply Quote 0
        • K Offline
          kybasche
          last edited by

          amazing how easy things are sometimes.

          guess i have a long way to go πŸ˜„

          thanks!

          D

          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