π‘ LightUp 7.1 | SketchUp's only real-time renderer that uses object-based rendering
Download Trial
Sharing variables between functions
-
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
-
Hi Derek,
Make variable a a class instance variable e.g.@a.
def self.Box()
@a = 5
b = 6
c = @a * b
end #Boxdef self.Circle()
d = 12
e = d * @aend #module
-
amazing how easy things are sometimes.
guess i have a long way to go
thanks!
D
Advertisement