Note: the following issue may be a lack of my python knowledge, or a bug (possibly linked to the issue described in the linked topic).
Anyway, I’d be happy to get some answers.
So. I want to manipulate lists. For example remove the enemy hero from the list of enemies; or add myself to the list of friends, etc. However, the lists do not change.
Examples:
enemies = self.findEnemies()
self.say(enemies)
# output: Alpha, Bravo, Charlie
enemies.remove("Alpha")
self.say(enemies)
# output: Alpha, Bravo, Charlie
enemies.append("Delta")
self.say(enemies)
# output: Alpha, Bravo, Charlie
enemies.pop[0]
self.say(enemies)
# output: Alpha, Bravo, Charlie
del enemies[0]
# unexpected token
self.say(type(enemies))
# type is not defined
If I convert such a list using list()
I get absolutely the same results, but in square brackets:
enemies = list(self.findEnemies())
self.say(enemies)
# output: [Alpha, Bravo, Charlie]
enemies.remove("Alpha")
self.say(enemies)
# output: [Alpha, Bravo, Charlie]
# etc.
If I compile the list myself then .append()
works, but the rest doesn’t:
targets = self.findEnemies()
enemies = []
for target in targets:
enemies.append(target)
self.say(enemies)
# output: [Alpha, Bravo, Charlie]
…or even worse: .remove()
removes the last element, not the one in the parameter:
# enemies comes from the above code
enemies.remove("Alpha")
self.say(enemies)
# output: [Alpha, Bravo] (!!!)
I can make a workaround by creating the lists myself, and add/exclude certain items manually. However, it’s far from the desired behavior…