Notifications
Clear all

[Closed] Struct for loop?

I was just wondering… is there anything like a for loop but for structs and properties instead of arrays and elements?


Edit:
To clarify, I’m looking for a way to be able to get this sort of result without relying on execute:

test = testStruct first:1 second:2 third:3 fourth:"testing"
   testProps = getPropNames test
   
   for p = 1 to testProps.count do
   (
   propName = testProps[p] as string
   propVal = execute ("test." + propName)
   format "%: %
" propName (propVal == "testing")
   )

Which returns

#Struct:testStruct(
    fourth:<data>; Public,
    second:<data>; Public,
    first:<data>; Public,
    third:<data>; Public)
  (testStruct first:1 second:2 third:3 fourth:"testing")
  #(#fourth, #second, #first, #third)
  fourth: true
  second: false
  first: false
  third: false
  OK
  OK
6 Replies
1 Reply
(@easyfrog)
Joined: 10 months ago

Posts: 0

Is it Your want ??


struct testStruct 
(
	first = 1,
	second = 2,
	third = 3,
	fourth = "testing",
	
	fn testFn = (
		"Is a function"
	)
)

test = testStruct()

ps = getPropNames test

for p in ps do (
	val = getProperty test p
	format (p as string + " = % , type is % 
") val (classof val) 
)

Result :

fourth = testing , type is String
testFn = testFn() , type is MAXScriptFunction
second = 2 , type is Integer
third = 3 , type is Integer
first = 1 , type is Integer

What the heck? That’s what I tried doing initially and it didn’t work. But now later when I tried it again, it worked fine. I must have screwed something up the first time…

Oh well, thanks for the help

But the not great is the sequence… How to get it like this :first second third fourth… :shrug:

2 Replies
(@pjanssen)
Joined: 10 months ago

Posts: 0

It would seem like something has changed in either 3dsMax 2012 or 2011:
2010: ps = #(#fourth, #testFn, #second, #third, #first)
2012: ps = #(#first, #second, #fourth, #third, #testFn)
2013: ps = #(#first, #second, #fourth, #third, #testFn)

(@easyfrog)
Joined: 10 months ago

Posts: 0

I use 2012 But sequence is Changed every time you restart the MAX…

Lawl Max y u so silly?

Yeah, it’s kinda strange that structs won’t keep things in any consistent order. That’s not going to be a problem for me in this case, but I can definitely foresee situations where it would become irritating.