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

Question #99

Open
guygit opened this issue Jan 6, 2025 · 1 comment
Open

Question #99

guygit opened this issue Jan 6, 2025 · 1 comment

Comments

@guygit
Copy link

guygit commented Jan 6, 2025

Hi there,

thx for creating this fantastic implementation of BT!

In my use case I want to update the style (css) of a certain element and I wonder how to pass a "context" (e.g. an arbitrary state object) into the agent, that would then update the state in the BT.Action.

In the following code snippet you can see how pass some context in - but i wonder how to get it out again?

Thank you!

export const getAgent = (state: Signal<GridItemState>) => { return { isHeaderFixed: () => { console.log('Checking if header is fixed: ', state.value.r1c2.fixed); return state.value.r1c2.fixed ? true : false; }, setHeaderPosition: () => { console.log('Setting header position ', this); return State.SUCCEEDED; } }; }

@nikkorn
Copy link
Owner

nikkorn commented Jan 9, 2025

Thanks very much!

So the library can't pass any custom state when invoking any agent functions, the library was designed to avoid having to deal with any agent state and to only be concerned with behaviours. The idea is that any state would already be accessible to the functions invoked by mistreevous.

In your scenario is it not possible to add the state to the agent that you are creating in getAgent and just have isHeaderFixed reference that?

It's a little difficult to give you an answer without clearer picture of your actual implementation and how/where getAgent is being called.

What do you mean by "get it out again"?

Can you share the tree definition you are using?

Thanks

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

No branches or pull requests

2 participants