printing description based on object list.

what i'm trying to is match object with a description(that will go in room descirpotn) without using a ton of seperate IF statements

list add (obj, object1)
list add (obj, object2)
desc = NewStringlist()
list add = (desc, "this is object1")
list add = (desc, "this is object2")
foreach (x, obj) {
  if (ListContains(ScopeReachable(), x)) {
    msg ("message")
  }
}

in this case, it prints message twice for the test(both objects in same room at the moment). Objects are randomly scattered at the start of the game si don't know which items will be in what room. or would a large IF statement function be better?


Do the objects have the same description in each room they might be found in?

If so, try enabling "In-room descriptions" on the game's 'Features' tab.
That will allow you to give any object a line of description which will automatically be added to the end of the description for the room it is in.


If your descriptions are different for each room (for example if they describe where in the room an object is), it may be better to use a dictionary like this:

obj_descr = NewStringDictionary()
dictionary add (obj_descr, "object1", "there is an object1 on the floor.")
dictionary add (obj_descr, "object2", "there is an object2 on a shelf in the corner.")
dictionary add (obj_descr, "object3", "object3 is leaving a stain on the carpet.")

foreach (obj, ScopeReachableNotHeld()) {
  if (DictionaryContains (obj_descr, obj.name)) {
    msg (StringDictionaryItem (obj_descr, obj.name))
  }
}

You could also make the dictionary an attribute of the room, so you don't have to create it every time.


Or turning that last piece of code so that it behaves like your example:

obj_descr = NewStringDictionary()
dictionary add (obj_descr, "object1", "there is an object1 on the floor.")
dictionary add (obj_descr, "object2", "there is an object2 on a shelf in the corner.")
dictionary add (obj_descr, "object3", "object3 is leaving a stain on the carpet.")

scope = ScopeReachableNotHeld()
foreach (key, obj_descr) {
  obj = GetObject (key)
  desc = DictionaryItem (obj_descr, key)
  if (ListContains (scope, obj)) {
    msg (desc)
  }
}

(the difference being that this will list objects in the order they appear in the dictionary, whereas the previous will show them in the order they appear in the object tree at the left of the editor window)


Log in to post a reply.

Support

Forums