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!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Uninitialized class variable

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 2 Posters 966 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.
    • PixeroP Offline
      Pixero
      last edited by

      I'm trying to make a script remember the values the user puts in during a SketchUp session so that he wont have to re enter them every time the script is run.

      When for example using:

      module Mymodule
        class Myclass
      
        def initialize
          #Setting default values
          @myvariable = 25.mm unless @myvariable 
      
          #And so on......
      

      the script works but wont remember the settings when run again.

      When using @@myvariable = 25.mm unless @@myvariable
      I get a "Uninitialized class variable" error message.

      What am I doing wrong?

      1 Reply Last reply Reply Quote 0
      • PixeroP Offline
        Pixero
        last edited by

        Should it be @@myvariable = nil and then @myvariable with just one @ or was that a typo?

        1 Reply Last reply Reply Quote 0
        • sdmitchS Offline
          sdmitch
          last edited by

          @pixero said:

          Should it be @@myvariable = nil and then @myvariable with just one @ or was that a typo?

          I just copied your code and added the @@myvariable=nil to it. The typo, @myvariable, was in your original code.

          It should be @@myvariable everwhere.

          Nothing is worthless, it can always be used as a bad example.

          http://sdmitch.blogspot.com/

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            @pixero said:

            I'm trying to make a script remember the values the user puts in during a SketchUp session so that he wont have to re enter them every time the script is run.

            When for example using:

            module Mymodule
            >   class Myclass
            > 
            >   def initialize
            >     #Setting default values
            >     @myvariable = 25.mm unless @myvariable 
            > 
            >     #And so on......
            

            the script works but wont remember the settings when run again.

            When using @@myvariable = 25.mm unless @@myvariable
            I get a "Uninitialized class variable" error message.

            What am I doing wrong?

            You just need to make a dummy assignment to it just after class declaration.

            module Mymodule
              class Myclass
              @@myvariable=nil
              def initialize
                #Setting default values
                @@myvariable = 25.mm unless @myvariable 
            
                #And so on......
            

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • PixeroP Offline
              Pixero
              last edited by

              Thanks, that worked.

              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