getting a structs var name &&|| passing global vals to local with variable var name


#1

heyho,
ok im trying to create a few functions to make the work with structs more simple and allow to redefine them on the fly, add vars, remove vars, ect…
now i ran into a bit of a snag with this as i wanted to pass a global struct to local scope with variable struct name(s)… take a look


(
	clearlistener()
	struct struct1 
	(
		a = 0 ,
		a2,
		b = 13
	)
	
	fn structAddVar str var2Add val2Add Name:"" isGlobal:false =
	(
		local propNames = getPropNames str
		local temp = str()
		local props = for prop in propNames collect getProperty temp prop
		
		local stri = ""
		stri += "struct "+ (if classOf name == string then name else "conStructorTempStr") + " 
"
		stri += "("+"
"
		for i = 1 to propNames.count do 
		(
			stri += propNames[i] as string + " = " + props[i] as string + ",
"
 		)
		stri += var2Add as string + " = " + val2Add as string + "
"
		stri += ")"+"
"
		
		execute stri
		
		local tStruct = copy conStructorTempStr --problem :P how in the world am i supposed to get it into a local scope with variable name ?! 
		if not isGlobal do execute (if classOf name == string then name else "conStructorTempStr" + " = undefined")
		
		return tStruct
	)--END structAddVar FN
	
	structAddVar struct1 #c 27 Name:"theTestStruct"
)

as you see everything works fine if i only have the one preDefined name for the structs… but thats not the point of the whole thing so my question is: how would i go about getting that struct into a local scope with a changing (var) name?

thx for you time


#2
(
	clearlistener()
	struct struct1 
	(
		a = 0 ,
		a2,
		b = 13
	)
	
	fn structAddVar str var2Add val2Add Name:"" isGlobal:false =
	(
		local propNames = getPropNames str
		local temp = str()
		local props = for prop in propNames collect getProperty temp prop
		
		local stri = ""
		if name=="" do name = "conStructorTempStr"
		stri += "struct "+ name + " 
"
		stri += "("+"
"
		for i = 1 to propNames.count do 
		(
			stri += propNames[i] as string + " = " + props[i] as string + ",
"
 		)
		stri += var2Add as string + " = " + val2Add as string + "
"
		stri += ")"+"
"
		
		execute stri
		print name
		
		local tStruct = copy (execute name) --problem :P how in the world am i supposed to get it into a local scope with variable name ?! 
		if not isGlobal do execute (if classOf name == string then name else "conStructorTempStr" + " = undefined")
		
		return tStruct
	)--END structAddVar FN
	
	structAddVar struct1 #c 27 Name:"theTestStruct"
)

Is this what you’re going for? I’m not sure…


#3

oh…that was simple…damn :smiley:
thx man


#4

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.