Foreach random object help(Solved)

Zubric
25 Jan 2020, 23:46I need help to figure out if it possible to run and Foreach segment on an objectlist. Foreach object in the list Randomly choose a room and move each object to said room. i'm unsure how to format the MoveObject segment to do such a thing. My workaround is below
list add (rooms, Strange Room)
list add (rooms, warehouse)
pickroom = GetRandomInt(0,1)
MoveObject (circle box, ObjectListItem(rooms,pickroom))
pickroom = GetRandomInt(0,1)
MoveObject (square box, ObjectListItem(rooms,pickroom))
pickroom = GetRandomInt(0,1)
MoveObject (triangle box, ObjectListItem(rooms,pickroom))
pickroom = GetRandomInt(0,1)
MoveObject (pentagon box, ObjectListItem(rooms,pickroom))
mrangel
26 Jan 2020, 00:25With a foreach, that would look like:
list add (rooms, Strange Room)
list add (rooms, warehouse)
boxes = (some code that gives you a list of objects)
foreach (box, boxes) {
MoveObject (box, PickOneObject (rooms))
}
If I was doing this, I'd probably put all the boxes in a temporary room before randomising them, so I can just get the list by doing: boxes = GetDirectChildren (temporary room)
Or if you want to include a longer list in your code, you could do:
roomnames = Split ("storage room;warehouse;armoury;somewhere else")
boxnames = Split ("square box;circle box;triangle box;pentagon box")
foreach (boxname, boxnames) {
roomname = PickOneString (roomnames)
MoveObject (GetObject (boxname), GetObject (roomname))
}

Zubric
26 Jan 2020, 01:26Oh thank you, I didn't know pickoneobject existed, rather new at this. Cool