SelinaDev / Godot-Roguelike-Tutorial

Yet Another Roguelike Tutorial in Godot
MIT License
102 stars 11 forks source link

restored inventory items are missing the 'entity' member variable #19

Closed rosskarchner closed 8 months ago

rosskarchner commented 9 months ago

I'm sure I'm just missing something here. After I got things working through part 10, I noticed that inventory items don't work after being restored from save, all related to 'entity' being null:

"Invalid call. Nonexistent function 'get_entity_name' in base 'Nil'". at this line: https://github.com/SelinaDev/Godot-Roguelike-Tutorial/blob/main/part_10/src/Entities/Actors/Components/healing_consumable_component.gd#L16

"Cannot call method 'queue_free' on a null value." at this line: https://github.com/SelinaDev/Godot-Roguelike-Tutorial/blob/main/part_10/src/Entities/Actors/Components/consumable_component.gd#L16

I don't have the same problem running the project from this repo, but can't find what I'm doing different. Do you have any ideas?

Thank you!

rosskarchner commented 9 months ago

I figured out this one: This line here doesn't appear in the tutorial text, but is important:

https://github.com/SelinaDev/Godot-Roguelike-Tutorial/blob/main/part_10/src/Entities/entity.gd#L113

SelinaDev commented 9 months ago

Thank you very much for pointing me to this! I will be sure to uptate the tutorial to include this as soon as I get the chance.

rosskarchner commented 9 months ago

Here's one more thing I found-- there were some edits to main_game_input_handler.gd

The symptoms I noticed were:


>   
68,71d68
<   if inventory.items.is_empty():
<       await get_tree().physics_frame
<       MessageLog.send_message("No items in inventory.", GameColors.IMPOSSIBLE)
<       return null
77,79c74
<   var has_item: bool = selected_item != null
<   var needs_targeting: bool = has_item and selected_item.consumable_component and selected_item.consumable_component.get_targeting_radius() != -1
<   if not evaluate_for_next_step or not has_item or not needs_targeting:
---
>   if not evaluate_for_next_step or (selected_item and selected_item.consumable_component and selected_item.consumable_component.get_targeting_radius() == -1):
91,92d85
< 
< 
SelinaDev commented 8 months ago

Thank you again, sorry it took so long. I just updated the site to include these changes.