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

Support for variables #15

Open
bhouston opened this issue Oct 12, 2022 · 3 comments
Open

Support for variables #15

bhouston opened this issue Oct 12, 2022 · 3 comments

Comments

@bhouston
Copy link
Contributor

I've added explicit support for creating typed variables with default values. Right now variables are discarded when loaded into behave-flow.

There are a number of examples here: https://github.com/bhouston/behave-graph/tree/main/src/graphs/core/variables

@beeglebug
Copy link
Owner

image

I've made a start on this, but have a question. In the image above, there is a float variable, but the "variable" input sockets on the Set and Get nodes both have a valueType of "id", which is causing an issue.

At the moment, sockets can only be connected when valueTypes match (float -> float, flow -> flow etc), from a user perspective, it would make sense for a float variable to only be able to connect to matching nodes, but the data for that decision is not self contained on the socket spec.

I could potentially add special logic which, when it encounters an "id" variable type, it looks at the other non-flow sockets on the node for a valueType, in this case it would find "float".

@beeglebug
Copy link
Owner

Thinking about this some more, i think its right that "id" is its own valueType so that variables can only be connected to variable slots (similar to flow sockets), perhaps I just need to add some custom logic at the point a connection is attempted to check the variable type also matches.

This still leaves the question of how to determine the type, at the moment I think its only get/set nodes which have variable sockets, in which case the correct valueType is whatever the value of the sole non-flow non-variable socket is, but is this universally true?

@bhouston
Copy link
Contributor Author

I came up with a different solution by looking at Unreal Engine's blueprints. What they do is that after you have "declared" variables by adding variable entries to their list of variables, it create new nodes that include basically the name of the variable in their name.

Basically if you declare a "count" variable in a blueprint, you can now create nodes of type "get count" and "set count" in which the value socket is of the same value type of "count."

I've implemented this pattern in the behave-graph library recently. So we can mimic it.

The node names in the JSON would be "variable/set/${variable.id}" and "variable/get/${variable.id}".

I've made these two functions that dynamically create these nodes:

https://github.com/bhouston/behave-graph/blob/main/src/lib/Profiles/Core/Variables/VariableSet.ts#L9
https://github.com/bhouston/behave-graph/blob/main/src/lib/Profiles/Core/Variables/VariableGet.ts#L8

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