-
Notifications
You must be signed in to change notification settings - Fork 67
Add nil check when replaced Pokemon not found #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: releases
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a nil check to prevent a crash in the getNewLegendaryFusionForGymType function when pokemon_to_be_replaced is nil. The fix allows the legendary mode to continue without crashing, though it results in a non-legendary Pokémon being used when the nil case occurs.
Key Changes
- Added a nil check wrapper around lines 127-131 to prevent accessing properties on a nil object
- Preserved existing logic for determining which species to replace with a legendary
Comments suppressed due to low confidence (1)
Data/Scripts/052_InfiniteFusion/System/GameModes/LegendaryMode.rb:119
- The else block on line 117 has a logic error that causes
pokemon_to_be_replacedto be nil. Whenbase_pokemon_with_gym_typeis empty (which triggers early return on line 108), this block should never execute. However, the comment says 'Neither have the type', which contradicts the empty check. The real issue is thatpokemon_to_be_keptis set to.sampleon an empty array (returns nil), then subtracting[nil]from an empty array and calling.firstreturns nil. This entire else block appears unreachable due to the early return on line 108, suggesting dead code.
else #Neither have the type, just pick at random
pokemon_to_be_kept = base_pokemon_with_gym_type.sample
pokemon_to_be_replaced = (base_pokemon_with_gym_type - [pokemon_to_be_kept]).first
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| head_species_id = legendary_species | ||
| else | ||
| body_species_id = legendary_species | ||
| end |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation detected: lines 128 and 131 use tabs while line 130 uses spaces. This should be standardized to match the project's style (appears to be 2 spaces based on surrounding code).
| head_species_id = legendary_species | |
| else | |
| body_species_id = legendary_species | |
| end | |
| head_species_id = legendary_species | |
| else | |
| body_species_id = legendary_species | |
| end |
|
This is already fixed in a way that results in a legendary. Just waiting on a new release. infinitefusion/scripts@baf223e |
|
Cool. I'll just keep my fix local until next release, then. 👍 |
Currently the game will crash at line 126 of
getNewLegendaryFusionForGymTypeifpokemon_to_be_replacedis Nil.Adding a Nil check on line 126 safely guards against this at the cost of this trainer having a non-legendary Pokemon in their roster, in this case Marowak. (screenshot just do display error no longer occurs)