How to create an list and call it in a function

So, my goal here is to move many objects at once to different locations in one piece of code. I tried to use a string list in an attribute on an object but couldn't code it, so the list of objects and where they should be moved to would be executed. Then I thought I using an object list but I couldn't figure that out either. And it would really only be good to move objects on mass to the same location.
How do I do this?


In most cases, adding an object to a list is more work than just moving it. There's only a few situations I could see this being useful.

I suppose you could have a function named MoveObjects with parameters list and destination and the code:

if (TypeOf (list) = "string") {
  list = Split (list)
}
foreach (obj, list) {
  if (TypeOf (obj) = "string") {
    obj = GetObject (obj)
  }
  if (TypeOf (obj) = "object") {
    if (not obj = null) {
      obj.parent = destination
    }
  }
}

That would make things slightly simpler because you could do something like:

MoveObjects ("bell;book;candle", altar)

But it does seem like a really tiny advantage.


That last suggestion does seem like my best bet, but it would not help if different objects go to different rooms.
Would it be possible to write a string list as an attribute on an object with the code of move object with the object and destination in each of the lists spaces, then when called, it executes all strings on the list?


I think something like that should be possible, but I'm still not sure why you would want to. Why not just make a script that moves all the objects to where you want them?

If you want to code both the object and its destination, it makes more sense to use a dictionary. So, here's a sample function MoveObjects which has a single parameter, dict.

foreach (key, dict) {
  obj = GetObject (key)
  if (not obj = null) {
    destination = DictionaryItem (dict, key)
    if (TypeOf (destination) = "string") destination = GetObject (destination)
    if (not destination = null) {
      obj.parent = destination
    }
  }
}

You could call this something like:

stuff_to_move = NewDictionary()
dictionary add (stuff_to_move, "bell", church)
dictionary add (stuff_to_move, "book", library)
dictionary add (stuff_to_move, "candle", pantry)
MoveObjects (stuff_to_move)

Of course, this is more code than just moving the objects directly. But you could use an attribute instead of the local variable stuff_to_move, so you can make the dictionary at one point and then move all the objects later.

You could also use it with the QuickParams function, but this is limited (I can't remember if it's a maximum of 3 or 4 dictionary items this way):

MoveObjects (QuickParams ("object1", "room1", "object2", "room2", "object3", "room3"))

Note that in this example, the rooms can be given either as a room object, or a string containing the exact name of the room. The objects must be a string, because only strings can be used as dictionary keys.


That is helpful and one option, but I was hoping to use an attribute string list because I could designate where each object goes individually and move them as one function. I want to move objects from different rooms to a single one, but what do I do when I want to return them? Write out each move object and make the code needlessly longer. Plus, with an attribute code list, it is more organized and easy to edit and add things. Just Moveobject after moveobject in a line would get really confusing and hard to navigate.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums