transit system

sorry but I am very new at this and I have seen an error where I don't understand exactly what's going on

Could not set value 'not ObjectDictionaryItem(game' - The number of opening brackets "(" does not match the number of closing brackets ")".
here is the code:

  msg ("No buses stop here.")
}
else {
  sl = NewStringList()
  foreach (key, game.destinations) {
    if (not ObjectDictionaryItem(game.destinations, key) = player.parent) {
      list add (sl, key)
    }
  }
  ShowMenu ("Where do you want to go?", sl, true) {
    dest = ObjectDictionaryItem(game.destinations, result)
    msg ("You take the bus to " + result)
    player.parent = dest
  }
}

I am using the online version too. apologies for bad english thank you


The parser sometimes has issues with function calls inside an expression. That's the downside of allowing object names to contain spaces and symbols.

I don't know the exact rules, but you could try:

    if (not ObjectDictionaryItem (game.destinations, key) = player.parent) {

or

    if (not player.parent = ObjectDictionaryItem (game.destinations, key)) {

or if all else fails:

    destination = ObjectDictionaryItem (game.destinations, key)
    if (not player.parent = destination) {

The problem is that it's treating ObjectDictionaryItem(game as the name of an object which has a destinations attribute; and then finding an extra ) that it wasn't expecting.


Actually… there's probably an easier way to do what you're trying to do.

It looks like game.destinations is an objectdictionary; where the key is the alias of a room, and the value is the room itself. Is that correct?

If so, it's probably easier to have game.destinations as an objectlist, then you could achieve the same effect by doing:

  msg ("No buses stop here.")
}
else {
  ShowMenu ("Where do you want to go?", ListExclude (game.destinations, player.parent), true) {
    dest = GetObject (result)
    msg ("You take the bus to " + GetDisplayAlias (dest))
    player.parent = dest
  }
}

If the names in the dictionary/menu are different from the rooms' aliases for some reason, then this doesn't apply. You got a good approach; but making it a stringdictionary (keys are object names, values are the text to show the player) would let you do:

  msg ("No buses stop here.")
}
else {
  ShowMenu ("Where do you want to go?", game.destinations, true) {
    dest = GetObject (result)
    msg ("You take the bus to " + DictionaryItem (game.destinations, result))
    player.parent = dest
  }
  JS.eval ("$('#" + game.menuoutputsections + " div:has(.cmdlink[onload*=\"MenuResponse\\',\\'" + player.parent.name + "\\'\"])').remove();")
}

(That's probably more efficient code, but harder to read; not even sure I got the toothpicks right off the top of my head)


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

Support

Forums