Setting a specific item in a list

Hey folks!

In the course of working on SaveStateLib, I found a slightly more efficient way to set a given value in a list. In case anyone is interested:

<function name="SetListItem" parameters="list, index, value">
  while (index > ListCount (list)) {
    // this is a bit ugly; best behaviour will depend on why you're using this
    // the case I'm using it for, this can't happen
    list add (list, null)
  }
  if (index = ListCount (list)) {
    list add (list, value)
  }
  else {
    for (i, 0, ListCount(list) - 1) {
      item = ListItem (list, 0)
      list remove (list, item)
      if (i = index) {
        item = value
      }
      list add (list, item)
    }
  }
</function>

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

Support

Forums