ScriptSpot home

Forum topic · General Scripting

random objects in a list

By titane357 · 2009-12-30

Description

Hello

I have a problem : I know how to make a random action on an objects list,
but I can figure to make an action on all a list randomly :
- I have ten objects (for e.g.)
- I want to rotate each object of the list but in random order (the 2nd, the 8th, ...)

Something like : "for obj in sel in randommanner do"....

Thanks.

Comments (7)

Comment policy

K

Thanks Anubis I was searching for a solution to this problem and you came up with the goods...again!

titane357

You are right Anubis !!! Works great now ! Thanks :-))

Panayot Karabakalov

No Superman, hehe... and for the selection - you need to convert it to array, i.e:

intArray = selection as array
titane357

Thanks Anubis (or do I must call you Superman ?)
If I understand well intArray can be declared like this : intArray=selection ?
if so I have a problem : Max don't seems to like "deleteItem intArray rndIndex" , I have an error message : No "deleteItem" function for $selection

Panayot Karabakalov

maybe something like this...

intArray -- all collected objects
while intArray.count > 0 do (
    rndIndex = random 1 intArray.count
    obj = intArray[rndIndex] -- get random obj from array
    -- What TO DO with obj - code here...
    deleteItem intArray rndIndex
)
Marco Brunetta

Well, suppose you have all the objects on an array. You probably know you can access items on an array using their index number, so all you need is a way of generating a random index number...

I'm sure you can figure it out from that...

Reply to Marco Brunetta
titane357

hello Marco,
the thing I can't imagine is to acces randomly to these array indexes but one time for each object :
I was thinking to
- make an array for all the objects
- make a random number of the size of the array
- make an action with this object
- make a new array without this object
- make a new random number of the size of this new array
etc...
bur I don't know how..... :-((