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

Some nodes can only use fixed values #224

Open
CodeLazier opened this issue Sep 21, 2024 · 9 comments
Open

Some nodes can only use fixed values #224

CodeLazier opened this issue Sep 21, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@CodeLazier
Copy link

Problem statement

Can built-in decorator nodes only use fixed values? For example, the Duration of Cooldown and the Run Limit of RunLimit can be changed to refer to BBNode, similar to the animation playback node of Scene, which greatly increases flexibility.Even all the properties can be set directly or by code using BBNode.

Proposed solution

none

Alternatives

none

@CodeLazier CodeLazier added the enhancement New feature or request label Sep 21, 2024
@limbonaut
Copy link
Owner

BBNode is not designed to reference an object property. It's strictly for referencing nodes. It's also not a recommended approach to reference nodes directly from a BehaviorTree.

@CodeLazier
Copy link
Author

CodeLazier commented Sep 21, 2024

So what are the best practices for those who need runtime changes? Can I only use BTask to implement the functions that the decorator already has?

Fixed: BBNode -> BBParam

@CodeLazier
Copy link
Author

CodeLazier commented Sep 21, 2024

I've found that it's possible to define the value of the setting yourself by inheriting from the decorator class.
I think that's the best thing to do.tks!

But it seems that inheritance doesn't implement the built-in logic, so I'll confirm it when I look into it

@limbonaut
Copy link
Owner

Ah, you meant BBParam. I tried to use BBParam only where it's most needed, because it takes more clicks to edit parameters in GDExtension (unlike in module version). If this PR gets accepted, we can adopt it more widely:

@CodeLazier
Copy link
Author

CodeLazier commented Sep 22, 2024

Extending BTDecorator does what I expected so far, but Limboai demo doesn't seem to have an example of this.
I thought it was in BTDecorator If a SUCCESS is returned in the _tick method, Limbo will automatically execute its child node.
But tested it wasn't the case, I needed to call it manually.

For example, if I want to implement my own defined BTColldown decorator, then:

extends BTCooldown

func _setup() -> void:
	duration = agent.attack_frequency


func _tick(delta: float) -> Status:
	return get_child(0).execute(delta)

The above code didn't work, didn't extend BTCooldown, so I ended up choosing to extend BTDecorator

extends BTDecorator

@export var duration: float

var _time: float = 100

func _setup() -> void:
    duration = agent.attack_frequency


func _tick(delta: float) -> Status:
    if _time > duration:
	_time = 0
	return get_child(0).execute(delta)

    _time += delta
    return FAILURE

@limbonaut
Copy link
Owner

limbonaut commented Sep 22, 2024

For example, if I want to implement my own defined BTColldown decorator, then

That's not how inheritance work. If you override _tick implementation, you override it fully, so cooldown functionality is no longer executed, and it is replaced by your own functionality, which is simply executing a child and returning its status. Have you tried not overriding _tick in that example?

@CodeLazier
Copy link
Author

CodeLazier commented Sep 22, 2024

If I don't override _tick method, then Cooldown will never execute the child node.

extends BTCooldown

func _setup() -> void:
	duration = agent.attack_frequency

If I don't cover anything, including _setup, that custom Cooldown works.

extends BTCooldown

use Godot4.4 dev2 test

@limbonaut
Copy link
Owner

Right, that may be a bug. Since you are overriding _setup it prevents BTCooldown from executing its own setup routine. It shouldn't override the existing setup behavior, I think, since setup is like a constructor in a sense.

@limbonaut
Copy link
Owner

Right, that may be a bug. Since you are overriding _setup it prevents BTCooldown from executing its own setup routine. It shouldn't override the existing setup behavior, I think, since setup is like a constructor in a sense.

Fixing it in #227.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants