Defold Adam - Overview

Intro

I want to share a project that has been in development for quite some time but never saw the light of day. It never saw the light of day simply because visual editing and good integration with Defold Editor turned out to be crucially important.

So, let me introduce Defold-Adam (In my story, Defold-Eva came first :upside_down_face:). It is a visual scripting plugin for Defold, similar to Playmaker for Unity. Initially, the idea was to describe each FSM (Finite State Machine) state separately in code, which was supposed to be somewhat convenient. However, it turned out that I would spend less time describing all the actions directly in code rather than describing states and transitions between them.

These issues are solved by creating a visual editor. Moreover, a good and well-thought-out one, better than the one in Panthera at the moment. But back then, I had not yet created such editors and decided to close the project. There are no current plans for its further development, but I have plans to share it with you so that you can take a look.

In this project I started writing the documentation right from the beginning. As I look at it now, it’s easy to understand how everything works based on the documentation. And that’s great! There will be less project description here. The documentation, the list of actions, and how the FSM works in Defold-Adam were taken from Playmaker with some modifications. But overall, if you know how Playmaker works, you will immediately understand how Defold-Adam works.

Disclaimer

Adam is a canceled project (there is even a small thread on Twitter), and I have no plans to revive it. The main issue is the lack of a good visual editor.

Adam contains a list of actions, similar to Playmaker, but not all of them have been implemented and tested. I am sharing about the project for educational and curiosity purposes, to showcase what was developed for Defold.

The main system is well-written, and for some games/prototypes the current system may even be useful and interesting to work with. Download the repository and take a look at a few examples to see how it works.


Started working on this example in Adam!

Defold-Adam

Defold-Adam - The FSM plugin for Defold to describe states like Playmaker in Unity with predefined actions.

Features:

  • Powerful: Finite State Machine to describe any behaviour you want
  • Easy to start: A lot of predefined actions with good API reference and annotations
  • Enough for game: Ability to build any game logic just via state machine (like Playmaker and Bolt in Unity)
  • Rich features: reusable action templates and nested FSM
  • Comfort: Any action describes in one line of code. It provides fast developing, easy reading and less bugs
  • Performance: Good performance even with a lot of instances of FSM
  • Visual Editor: not provided now, but who knows?
  • Code as Data: Ability to load your FSM as JSON (from resources, from web, etc). Need visual editor to make it :slight_smile:

Full README here

Actions

Actions in Adam are blocks of code that represent the minimal building units. Actions can be repetitive, deferred or delayed. Each action is described in a single line of code, making them easy to read and understand.

Example of a state with two actions:

adam.state(
	actions.transform.add_position(vmath.vector3(0, 10, 0), true),
	actions.go.delete_self(1)
)

State

States are sets of actions that need to be performed when transitioning to that state. All states are executed in the order they are defined. In the example above, there is one state that was used for projectile logic in the game. It moves upwards every frame and then gets deleted.

Events

Events are transitions between states. If there is a transition from the current state to another state based on a specific event, the FSM will transition to that state and execute all the actions associated with it. Currently, transitions are defined in the following way:

adam.new(idle, {
	-- {state_from, state_to, [trigger_event]}
	{idle, consume, actions.EVENT.TRIGGER_ENTER},
	{consume, idle},
	{idle, shoot, "on_fire"},
	{shoot, idle}
})

By default, the event triggering a transition is FINISHED, meaning that it occurs when all the actions in the current state are completed. However, some actions can be delayed or repetitive and in such cases, the FINISHED event will not be triggered.

Details

In addition to the main set of actions, states and transitions, there are some additional details that make Defold-Adam more convenient to use.

For example, it is possible to change the context of the Adam FSM, so it applies its logic to a different object instead of the current one. An example would be applying it to player projectiles. This way, you can have one Adam FSM for all projectiles without creating a .script file for each of them.

There is also the ability to use defined states within other states, creating action templates. Additionally, you can use an Adam FSM within another Adam FSM.

In my opinion, the system turned out to be quite flexible, but describing everything in code proved to be not the best idea.

Documentation

In this description, I didn’t dive into the details. If you’re interested, please take a look at the Adam documentation. It provides a comprehensive overview of all the capabilities of Defold-Adam that I have implemented and described.

Online Editor

Defold-Adam supports loading Adam FSM from JSON, which allows for the creation of an online editor where actions can be replaced on the fly and other functionalities can be added. However, as I mentioned earlier, I haven’t worked on a visual editor for it.

At the moment, I don’t see a significant advantage in doing so. But I think it would resemble what Playmaker currently offers.


From Adam examples

Links

Outro

Thank you for your attention! I hope you find it interesting to learn about Adam project and can find something useful for yourself. Leave your feedback and let us know what you liked the most!

:heart: Support :heart:

Your donation helps me stay engaged in creating valuable projects for Defold. If you appreciate what I’m doing, please consider supporting me!

Github-sponsors Ko-Fi BuyMeACoffee

17 Likes

Making a visual tool is a pain (in my work I do so and I hate it). I tried many times to start some projects for visual programming in Defold, I think mainly for shaders and rendering pipeline with live previews that would speed up development (and learning!) so much, but none of the attempts are completed/successful. It demands a lot of work, maybe some day, as a well organised open source project by many devs it could be possible, right now, I think it won’t happen in the nearest future :pensive:

Other than this I was checking Adam a while ago (still had this notice about it being cancelled) and got interested, but never had time to fully invest time into this, so thank you so much fro the write up, it clarifies a lot! :grin:

3 Likes

Yea visual editor to be able to make something like shadergraph in Unity would be really cool.