OK! Hard mode #godot challenge question:

Is there any way to set up a Resource with a signal that has a call bound?

By default, defining signals works fine but they cannot be bound in the editor. I have been using trashy workarounds. I would prefer to just bind the signal.

Ugh, the only answer I got to this was on BlueSky and was "why would you ever want something easy and useful? You should just do backflips like everyone else!"

I guess I'm glad for the silence here on Mastodon, at least it's not people telling me to not ask the question.

This is probably not Godot-specific, but I can't help except notice that whenever I ask a Godot question, 95% of the answers are about how I shouldn't have asked.

And then like 5% are "here's how:" and it's super easy.

Be part of the 5%.

Since it seems people don't know why you'd want this:

You have a Resource class: Potion.

How do you tell each type what it does?

Easiest way would be to bind arbitrary functions and args on a on_drunk Signal.

Otherwise you have to duplicate that functionality and it's either flabby or brittle. #godot

@view shouldn't potion should just be a node type? Why do you need it to be a resource?

@thebestnom Why would an inventory item be a node? It's a data object, not a functional scene object.

You just have a generic "item" node that shows an icon, links to a resource, and lets you choose whether to use it or sell it.

@view Can you have a kind of PotionManager, which job will be be to take a potion resource, figure out what to do and have all the signals connected to/from that manager ?
@uzakl You can, but the wiring ends up backwards. It's pretty clumsy.
@view I was going to have potions be things with a bag of effect components (can be an Array of the component Resources for example), and then when someone drinks a potion, you apply the effects to them. But I’m still figuring out ECS stuff.

@Taffer I think that's probably the best way to do it given the restrictions, but it's still a real annoyingly flabby way to go about it. It means you have to have a bunch of different classes you instantiate willy-nilly, saving and loading to a spreadsheet becomes really obnoxious-

It'd be so much nicer with a reflection-based function system. Sigh.

@view Yeah, I don’t want to have a big hierarchy of resources. I’ve been pondering a way to recreate things from a spreadsheet in a sensible way but haven’t written anything down yet.
@view It doesn’t show up in the GUI, but I think resources can have a _ready() function that can connect a signal for you. Not sure if you wanted them to hook up to a well known target or not.
@Taffer Creating custom code per resource is a massive amount of extra work, since it means each resource instance needs to be its own class and can't be meaningfully saved and loaded from a spreadsheet.
@view What are you connecting them to? If they all go to a manager class (or if a bunch of them do) you could write it once and then inherit from the resource that wires up the signal. I’m just making guesses though as I don’t know what you’re trying. (Been thinking about this lately for my game, no conclusion yet!)

@Taffer Itself would be enough.

The point is to have instances for, say, 100 different kinds of potion or whatever. Rather than each potion being its own subclass with custom code, you need a way to define what the potion does in the properties of the instance.

There's a few ways to do it, but they are all effectively "the things binding to signals already supports but you can't use that because fuck you".