{"id":23684903,"url":"https://github.com/chrsm/behave","last_synced_at":"2026-06-20T04:30:58.522Z","repository":{"id":130398892,"uuid":"392504109","full_name":"chrsm/behave","owner":"chrsm","description":"behavior tree lib for lua","archived":false,"fork":false,"pushed_at":"2021-08-07T23:32:05.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-13T14:59:23.105Z","etag":null,"topics":["love2d","love2d-library","lua","moonscript","yuescript"],"latest_commit_sha":null,"homepage":"","language":"MoonScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrsm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-04T01:12:00.000Z","updated_at":"2021-08-07T23:32:07.000Z","dependencies_parsed_at":"2023-06-26T06:16:35.082Z","dependency_job_id":null,"html_url":"https://github.com/chrsm/behave","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/chrsm/behave","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrsm%2Fbehave","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrsm%2Fbehave/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrsm%2Fbehave/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrsm%2Fbehave/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrsm","download_url":"https://codeload.github.com/chrsm/behave/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrsm%2Fbehave/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34557551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-20T02:00:06.407Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["love2d","love2d-library","lua","moonscript","yuescript"],"created_at":"2024-12-29T20:49:03.465Z","updated_at":"2026-06-20T04:30:58.515Z","avatar_url":"https://github.com/chrsm.png","language":"MoonScript","funding_links":[],"categories":["Love2D"],"sub_categories":["emacs"],"readme":"behave\n======\n\n`behave` is a [Behavior Tree][1] library for lua, written in [Yuescript][2].\n\nYou can build this repo from source with `make build` or download a [release][3].\n\n\nAPI\n===\n\n`behave`'s API is fairly straightforward. A behavior tree is given a set of\nnodes and runs through them when `:run()` is called. `:run` will pass any\narguments it receives to individual nodes' `:run` method.\n\n```\nbehave.Behavior\n\tbehave.Behavior(name, nodes)\n\t\tctor\n\n\t:add(node)\n\t\tadd a single node to the container\n\n\t:reset()\n\t\tresets all tracked state\n\n\t:getStatus(node)\n\t\treturns the status of a specific node as of the last execution.\n\t\tif the node has not been executed or can't be found,\n\t\tbehave.Node.status.unknown is returned.\n\n\t:run(...)\n\t\texecutes all nodes, tracking their status.\n\nbehave.Leaf\n\tbehave.Leaf(name, func)\n\t\tctor\n\t\t`func` is any function, and should return one of the statuses\n\t\tfrom `behave.Node.status`.\n\t\n\t:run(...)\n\t\texecutes `func` and returns the status.\n\nbehave.Selector\n\tbehave.Selector(name, { node1, node2, ... })\n\t\tctor\n\n\t\tthe nodes in the set can be of any type, but should be unique.\n\n\t:run(...)\n\t\texecutes each node until the first one returns a Node.status.success,\n\t\tat which point no further nodes are executed.\n\nbehave.Sequence\n\tbehave.Sequence(name, { node1, node2, ... })\n\t\tctor\n\n\t\tthe nodes in the set can be of any type, but should be unique.\n\n\t:run(...)\n\t\texecutes each node until the first Node.status.failure, at which\n\t\tpoint no further nodes are executed.\n```\n\nIf you have a set of behaviors fleshed out, you may want to apply ad-hoc changes\nto them before attaching to a new behavior set. You can use decorators for this.\nThey're currently a work-in-progress, though.\n\n```lua\nlocal behave = require(\"behave\")\n\n-- some already predefined behavior, imagine you've just imported it\nlocal l = behave.Leaf(\"walk around\", function()\n\t-- can't inject too much into something predefined, want to include it\n\t-- in a sequence but not have it trigger a failure?\n\treturn behave.Node.status.failure\nend)\n\n-- this decorator wraps it to never fail\nlocal new_l = behave.Decorators.Succeed(l)\n\n-- or invert it; if it fails, it succeeds, or vice-versa\nlocal new_l2 = behave.Decorators.Invert(l)\n\n-- or repeat it until some other condition is met\nlocal it = 0\nlocal new_l3 = behave.Decorators.Until(l, function()\n\tit = it + 1\n\n\t-- run 5 times\n\treturn it \u003e 5\nend)\n\nlocal s = behave.Sequence(\"do stuff\", { ..., l })\n```\n\nFull Example\n=======\n\n```lua\nlocal behave = require(\"behave\")\n\n-- \"nodes\" can be single units of work or groups - eg Selectors or Sequences\nlocal single = behave.Leaf(\"single-unit\", function(v)\n\tif v == \"example\" then\n\t\treturn behave.Node.status.success\n\tend\n\n\treturn behave.Node.status.failure\nend)\n\n-- a selector runs until the first node succeeds.\nlocal sel_leaf1 = behave.Leaf(\"sel-leaf-1\", function()\n\treturn behave.Node.status.success\nend)\n\nlocal sel_leaf2 = behave.Leaf(\"sel-leaf-2\", function()\n\tprint(\"I won't execute :(\")\n\n\treturn behave.Node.status.success\nend)\n\nlocal sel = behave.Selector(\"selector\", { sel_leaf1, sel_leaf2 })\n\n-- a sequence runs until the first node failure.\nlocal seq_leaf1 = behave.Leaf(\"seq-leaf-1\", function()\n\treturn behave.Node.status.failure\nend)\n\nlocal seq_leaf2 = behave.Leaf(\"seq-leaf-2\", function()\n\tprint(\"I won't execute :(\")\n\treturn behave.Node.status.success\nend)\n\nlocal seq = behave.Sequence(\"sequence\", { seq_leaf1, seq_leaf2 })\n\n-- behavior is a container for any type of node.\n-- it will run through all nodes it contains and track their state,\n-- executing them regardless of status.\nlocal b = behave.Behavior(\"behavior-one\", { single, sel, seq })\n\nb:run(\"example\")\n\nif b:getStatus(single) == behave.Node.status.success then\n\tprint(\"the single leaf succeeded!\")\nend\n\nif b:getStatus(sel) == behave.Node.status.success then\n\tprint(\"the selector succeeded!\")\nend\n\nif b:getStatus(seq) == behave.Node.status.failure then\n\tprint(\"the sequence failed!\")\nend\n```\n\nTODOs\n=====\n\n- [ ] implement more decorator types\n\n\n[1]: https://en.wikipedia.org/wiki/Behavior_tree_(artificial_intelligence,_robotics_and_control)\n[2]: https://github.com/pigpigyyy/Yuescript\n[3]: https://github.com/chrsm/behave\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrsm%2Fbehave","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrsm%2Fbehave","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrsm%2Fbehave/lists"}