I have looked at several other questions regarding this error and I still can't figure out what's wrong.
To select units, I have lists/arrays which draw from classes:
unit_orc_grunt = Unit("Grunt",[35,70,105,140,175,210,245,280,315,350],[35,70,105,140,175,210,245,280,315,350])
positions = numpy.array([
[unit_orc_grunt.locationx[0],unit_orc_grunt.locationy[0]],
[unit_orc_grunt.locationx[1],unit_orc_grunt.locationy[1]],
[unit_orc_grunt.locationx[2],unit_orc_grunt.locationy[2]],
[unit_orc_grunt.locationx[3],unit_orc_grunt.locationy[3]],
[unit_orc_grunt.locationx[4],unit_orc_grunt.locationy[4]],
[unit_orc_grunt.locationx[5],unit_orc_grunt.locationy[5]],
[unit_orc_grunt.locationx[6],unit_orc_grunt.locationy[6]],
[unit_orc_grunt.locationx[7],unit_orc_grunt.locationy[7]],
[unit_orc_grunt.locationx[8],unit_orc_grunt.locationy[8]],
[unit_orc_grunt.locationx[9],unit_orc_grunt.locationy[9]],
])
not_selected = [
positions[0],
positions[1],
positions[2],
positions[3],
positions[4],
positions[5],
positions[6],
positions[7],
positions[8],
positions[9]
]
selected = []
Then I have this in the game loop:
elif button_type[0] == 1:
for position in positions:
if numpy.any(position == not_selected) and numpy.any(position != selected) and mouse_position[0] >= position[0] and mouse_position[0] <= position[0] + character_width and mouse_position[1] >= position[1] and mouse_position[1] <= position[1] + character_height:
selected.append(position)
print("Position = ",position)
print("Selected Units = ",selected)
This works fine, and the selected units would then be drawn from the list 'selected', however, when I try to add the line not_selected.remove(position)
I received the error:
elif button_type[0] == 1:
for position in positions:
if numpy.any(position == not_selected) and numpy.any(position != selected) and mouse_position[0] >= position[0] and mouse_position[0] <= position[0] + character_width and mouse_position[1] >= position[1] and mouse_position[1] <= position[1] + character_height:
selected.append(position)
print("Position = ",position)
print("Selected Units = ",selected)
not_selected.remove(position)
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Why does selected.append(position)
work but not_selected.remove(position)
doesn't work here? How do I fix this?