Skip to content
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

Cannot set reference field value #79

Closed
VojtaStruhar opened this issue Aug 22, 2023 · 3 comments · Fixed by #81
Closed

Cannot set reference field value #79

VojtaStruhar opened this issue Aug 22, 2023 · 3 comments · Fixed by #81
Labels
🐛 bug Something isn't working

Comments

@VojtaStruhar
Copy link
Contributor

Godot version: v4.1.stable.official [970459615]

Describe the bug
When setting a reference property value, error is printed and the change doesn't happen.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Pandora panel with the example dataset (inventory)
  2. Under Items/Ores select CopperOre
  3. Change the CopperOre's rarity from currently Legendary to any other
  4. Error gets printed and the change doesn't go through

Error: Pandora error: value <Resource#-9223369595769779648> is incompatible with type reference

This happens even if I create a brand new category with new reference fields and items.

Expected behavior
The rarity of CopperOre should change and no error should be printed.

Desktop

  • OS: MacOS 13.4.1
@VojtaStruhar VojtaStruhar added the 🐛 bug Something isn't working label Aug 22, 2023
@VojtaStruhar
Copy link
Contributor Author

The issue is, that the PandoraReference class isn't considered of type "reference" and fails the is_valid_type check.

func(variant): return variant is PandoraEntity,

Adding PandoraReference to the type check should be fine, I think. I tried it, seemed to work just fine.

func(variant): return variant is PandoraEntity or variant is PandoraReference,

But I don't understand the codebase well enough (yet!) to be fully confident.

@bitbrain
Copy link
Owner

@VojtaStruhar the idea is that the reference gets created dynamically inside Pandora. From an API perspective, it should always be PandoraEntity.

Let me see today what the issue is here!

@VojtaStruhar
Copy link
Contributor Author

VojtaStruhar commented Aug 23, 2023

I dug a little more and found, that after selecting entity from a dropdown, you wrap it in PandoraReference and then call set_default_value with it:

# reference_property.gd, _ready
entity_picker.entity_selected.connect(
  func(entity:PandoraEntity):
    var reference = PandoraReference.new(entity.get_entity_id(), 1 if entity is PandoraCategory else 0)
    _property.set_default_value(reference)
    property_value_changed.emit())

But in set_default_value you have a very similar piece of code that does the same thing conditionally:

if value is PandoraEntity:
  value = PandoraReference.new(value.get_entity_id(), PandoraReference.Type.CATEGORY if value is PandoraCategory else PandoraReference.Type.ENTITY)

I think that in the entity_picker, we are wrapping the entity in a PandoraReference too early! I tried to pass in just the entity, seems to work just fine. I had a look in the stored data too - it seems to add the override correctly:

Copper ore rarity override - effect in stored data

If this sounds good to you, I'll make a pull request, it's a one-liner :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants