Dictionary with MobRefs as keys - possible bug?
Posted: Tue Jan 03, 2017 2:40 pm
Hello,
I am using dictionaries with MobRefs as keys in my AI and elsewhere, and now, with a core from around end of 2016 (not absolutely the last version, but a very current version) I seem to have a problem:
If I create several mobiles ad put their MobRefs into a dictionary, then I can use the dictionary as usual for finding the mobs by MobRef, I can delete specific mobs from the dictionary and so on.
But if a certain mob dies its MobRef cannot be deleted from the dictionary (this is only true for NPCs), it reports an error 'Object does not support members'! It seems to work if this is the last MobRef in the dictionary, and if the mobs are killed in the order they were inserted into the dictionary it also seems to work.
So - is it possible to delete a MobRef from a dictionary if the mob is dead? In my previous version of the core (around 2009 or so) this worked fine.
I have a spell which creates 3 mirror images of the caster. As long as they exist ('live'), the spell cannot be used again. The mirror images are simple identical NPCs, looking like the caster, but never moving or fighting, and they have 3 Hitpoints each. If they are killed, they disappear.
To control this, I add the 3 MobRefs to a dictionary, and afterwards check every 5 seconds, if the mobs still live. If a mob is dead, then I delete them using this loop:
The mobs in this spell disappear ('die') after a certain time, or they can be killed before that.
I think this could be a bug, since allowing MobRefs (as keys) in a dictionary should also allow erasing the keys (old MobRefs) of dead mobs. The MobRef exists, or the check mob.dead would no longer work.
Could somebody look into this? I will test further in the next few days...
OWHorus
I am using dictionaries with MobRefs as keys in my AI and elsewhere, and now, with a core from around end of 2016 (not absolutely the last version, but a very current version) I seem to have a problem:
If I create several mobiles ad put their MobRefs into a dictionary, then I can use the dictionary as usual for finding the mobs by MobRef, I can delete specific mobs from the dictionary and so on.
But if a certain mob dies its MobRef cannot be deleted from the dictionary (this is only true for NPCs), it reports an error 'Object does not support members'! It seems to work if this is the last MobRef in the dictionary, and if the mobs are killed in the order they were inserted into the dictionary it also seems to work.
So - is it possible to delete a MobRef from a dictionary if the mob is dead? In my previous version of the core (around 2009 or so) this worked fine.
I have a spell which creates 3 mirror images of the caster. As long as they exist ('live'), the spell cannot be used again. The mirror images are simple identical NPCs, looking like the caster, but never moving or fighting, and they have 3 Hitpoints each. If they are killed, they disappear.
To control this, I add the 3 MobRefs to a dictionary, and afterwards check every 5 seconds, if the mobs still live. If a mob is dead, then I delete them using this loop:
Code: Select all
// mirrors is a dictionary, containing MobRefs of previously created mobs (NPCs)
while (mirrors.size() > 0)
sleep(4);
foreach mirror in (mirrors.Keys())
if (!(mirror.dead == 0)) // This check works for player chars and NPCs
res := mirrors.erase(mirror); // Erase the MobRef (MobRef is the key)
if (!res) // This error check I added after finding, that it no longer works
print(res.errortext);
endif
endif
endforeach
sleep(1);
endwhile // If all mobs do not exist, the spell ends and can be cast again
I think this could be a bug, since allowing MobRefs (as keys) in a dictionary should also allow erasing the keys (old MobRefs) of dead mobs. The MobRef exists, or the check mob.dead would no longer work.
Could somebody look into this? I will test further in the next few days...
OWHorus