Archipelago icon indicating copy to clipboard operation
Archipelago copied to clipboard

Core: Add functions to check whether an Entrance/Region/Location exists

Open NewSoupVi opened this issue 1 year ago • 3 comments
trafficstars

People are doing goofy shit like

if entrance_name in self.multiworld.regions.entrance_cache[self.player]

and

try:
    self.get_entrance(entrance_name)
except KeyError:
    ...

in their world code. Let's stop that.

Alternatives

We could just make the get_[spot] methods return None if the spot doesn't exist. Maybe we could even add an optional argument called return_none_if_not_exists=False for the sake of worlds already relying on the KeyError behavior. (This would make that function significantly slower though)

We could also make alternative methods called try_get_[spot].

I thought this would be the simplest but I'm obviously willing to hear other opinions

Also:

Are the multiworld versions necessary? I'm not sure whether we should be adding multiworld methods for things at this point, I did it more out of "tradition" than anything

NewSoupVi avatar Mar 29 '24 10:03 NewSoupVi

I definitely prefer the try_get_[spot] -> Optional to [spot]_exists -> bool. I have no opinion on if making it a behavior of get_[spot] is better or not, though.

EmilyV99 avatar Mar 29 '24 10:03 EmilyV99

I definitely prefer the try_get_[spot] -> Optional to [spot]_exists -> bool. I have no opinion on if making it a behavior of get_[spot] is better or not, though.

Imma be honest I kinda just hate the name lol (also getting something to check whether it exists is pretty slow but that'd probably not be so bad, I don't think this would be a hot code path)

NewSoupVi avatar Mar 29 '24 10:03 NewSoupVi

Apparently this is not wanted so I guess someone can close it if they want to, I will never 😭

NewSoupVi avatar Mar 29 '24 14:03 NewSoupVi