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 #moduleThanks much!
Derek
-
-
amazing how easy things are sometimes.
guess i have a long way to go

thanks!
D
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement