Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CatRass |
I have code that adds a content into an array, through a series of check boxes, but want the user to be able to delete the specific item when they un-check the box. since the player can chose the options in a random order, I don’t think using the index of the array is a good solution. What would be?
Is there a reason you couldn’t use erase() to remove the item you needed to remove?
psear | 2020-06-17 10:00
Maybe I don’t understand how erase() works, but what I did was arrayName.erase(“variable I need to erase here”) and it erases the item with index 0. I also cannot use indexes to reference items, since when I remove an item the index will change, and since the options can be picked in a random order, I can’t assign items to a specific index.
CatRass | 2020-06-17 10:03
I think as mentioned in the other answer, a dictionary would work, and would also be more consistent if you had settings being enabled or disabled, rather than added or deleted. I haven’t seen your code, but I feel like that’s typically easier to manage.
psear | 2020-06-17 10:23