Keeping a container of Nodes Unique

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mattkw80

Some folks here helped my get my list of NPC ‘memories’ going - and now I’m hoping I can get help keeping these Nodes unique.

‘Memories’ can be thought of like items of inventory… apple, sword, rock, etc.
They are - ‘nodes’ but really just simple instances from the simple Memory Class I made.

+Memories (Node2d)

When I loop through them, how should I approach finding duplicates and pursing them?

ie: If Memory1 and Memory3 are both “I seen an apple the other day”… can someone help me with logic of iterating through and killing Memory1 because Memory3 is the same thing?

:bust_in_silhouette: Reply From: Inces

I think it is best to place such iteration at the moment of your NPC taking note of environment and preparing to appends it memory.

For memory in memories :
         if newmemory == memory :

Depending on how You organized this memory nodes, for example if You used dictionary or array You could also use : if memories.has(newmemory)

That’s… almost certainly going to work.

I’ll try it.

mattkw80 | 2021-03-31 18:36