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

Uninitialized class variable

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 2 Posters 915 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.
  • P Offline
    Pixero
    last edited by 3 Jun 2017, 19:21

    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
    • P Offline
      Pixero
      last edited by 3 Jun 2017, 20:05

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

      1 Reply Last reply Reply Quote 0
      • S Offline
        sdmitch
        last edited by 3 Jun 2017, 20:24

        @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
        • S Offline
          sdmitch
          last edited by 3 Jun 2017, 20:27

          @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
          • P Offline
            Pixero
            last edited by 4 Jun 2017, 12:23

            Thanks, that worked.

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

            Advertisement