Uninitialized class variable
-
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?
-
Should it be
@@myvariable = nil
and then@myvariable
with just one @ or was that a typo? -
@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.
-
@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......
-
Thanks, that worked.
Advertisement