PDA

View Full Version : getting a structs var name &&|| passing global vals to local with variable var name


Insanto
12-31-2010, 05:01 PM
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") + " \n"
stri += "("+"\n"
for i = 1 to propNames.count do
(
stri += propNames[i] as string + " = " + props[i] as string + ",\n"
)
stri += var2Add as string + " = " + val2Add as string + "\n"
stri += ")"+"\n"

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

lo
12-31-2010, 06:34 PM
(
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 + " \n"
stri += "("+"\n"
for i = 1 to propNames.count do
(
stri += propNames[i] as string + " = " + props[i] as string + ",\n"
)
stri += var2Add as string + " = " + val2Add as string + "\n"
stri += ")"+"\n"

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...

Insanto
01-01-2011, 12:30 AM
oh..that was simple..damn :D
thx man

CGTalk Moderation
01-01-2011, 12:30 AM
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.