ScriptSpot

Forum topic · General Scripting

GETTING VARIABLE AWAY FROM EXPRESSION

By kredka · 2013-11-13

Description

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. I tried with return as function and still nothing.
This is my code which search for missing plugins:
(
local t = stringstream ""
apropos "*missing*" to:t
t = t as string
local l = filterstring t "\n "
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)

Comments (3)

kredka · 2013-11-13

still nothing, won't work

.

miauu · 2013-11-13


(
	(
		local t = stringstream ""
		global lInst
		apropos "*missing*" to:t
		t = t as string
		local l = filterstring t "\n "
		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
				(
					lInst = getclassinstances cls
					
				----->VARIABLE I WANT TO GET VALUE FROM HERE IS: lInst
				)
			)
		)
	)
	format "lInst: % \n" lInst

Execute the code. The value of lInst will be printed in the listener. Then open maxscript listener, type lInst and press the numpad Enter.
I don't have missing plugins, so the value is always an epmty array.

barigazy · 2013-11-13

U already declared your variable as global.
Maybe is better to put it above

(
global llnst = #()
local t = stringstream ""
--. . . rest of the code
)