[Closed] getting variable away from expression
Maybe this is laughable question however I can’t handle with this one.
How to get variable “lInst” outside this code so I could use it in different place of code or diffrent script. Now when I check value of “lInst” inside this expression is different then outside.
This is my code which search for missing plugins:
(
local t = stringstream “”
apropos “missing” to:t
t = t as string
local l = filterstring t “
“
local lMissingClasses = #()
for t in l do
(
if matchpattern t pattern:“missing*” then
(
local cls = execute t
if matchpattern (cls as string) pattern:“missing*” then
(
global lInst = getclassinstances cls
—–>VARIABLE I WANT TO GET VALUE FROM HERE IS: lInst
)
)
)
)
—–>I WANT HAVE VALUE OF VARIABLE lInst HERE(outside expression above)
I would probably do this so your function returns your value.
Have a look in the maxscript help docs for ‘return’
Unfortunately it wan’t work, I stick to max help if my understanding is right I made it as a function find_missing_plg with return find_missing_plg inside also return lInst and there is nothing again.
Try creating/defining your global variable before your function definition and then in your function pass this global variable as a by-reference argument so your function updates its value.
global lInst
function find_missing_plg &plgArray =
(
local t = stringstream ""
apropos "*missing*" to:t
t = t as string
local l = filterstring t "
"
local lMissingClasses = #()
for t in l do
(
if matchpattern t pattern:"missing*" then
(
local cls = execute t
if matchpattern (cls as string) pattern:"missing*" then
(
append lMissingClasses (getclassinstances cls)
plgArray = lMissingClasses
--plgArray now contains the array of your missing classes
)
)
)
)
--then call your function
find_missing_plg &lInst
I’m not sure I’ve defined your function correctly– but pass by reference should work for you.
closer but not enough. I need get information about missingplugin to label or messageBox so
in order to acheive it I put this code under your line –plgArray now contains the array of your missing classes. when I call find_missing_plg &lInst I have error. When I put insteand of -messageBox i get like 1000x #(). Below my code still not working:
function find_missing_plg &plgArray =
(
local t = stringstream “”
apropos “missing” to:t
t = t as string
local l = filterstring t “
“
local lMissingClasses = #()
for t in l do
(
if matchpattern t pattern:"missing*" then
(
local cls = execute t
if matchpattern (cls as string) pattern:"missing*" then
(
append lMissingClasses (getclassinstances cls)
plgArray = lMissingClasses
--plgArray now contains the array of your missing classes
messageBox plgArray
)
)
)
)
–then call your function
find_missing_plg &lInst
Well, I don’t have 3dsMax to play with at the moment… but it would be best to move the following code line: plgArray = lMissingClasses
outside of the for loop… so it only gets assigned once after the loop finishes. Search maxscript help for printing formated results of array values. Sorry I can’t be of more help at the moment.