How to incorporate castagne into a story mode

Problem Description

I’m working on setting up the basic functionality of my game’s story mode, during which I’ll have scenes that transition to fights using castagne which then transition to different story scenes. But I’m completely lost on where to start with this, docs for full game creation are all to be written later. I’m well aware of Kronian Titans and its connection to castagne’s development so I know this is possible, just not how to do it myself.

In other words I want to be able to tell the game ‘enter a fight where player 1 is x character and player 2 is y character’ from a variety of custom scenes. And when that fight concludes to transition to scenes other than the normal post battle screen. I did a quick sketch of the story mode flow because better to overexplain than underexplain.

Technical Info

Castagne Version: 0.58
Host Engine: Godot3
Genre: 2D Fighter

Hello ! This is mostly handled by the flow module and Castagne’s singleton.
Basic implementation is likely way simpler than you might expect.

Starting up a Castagne fight is done fairly directly using Castagne.InstanceCastagneEngine(battleInitData = null, configData = null) from CastagneGlobal.gd.
The battleinitdata of course contains the definition of the two fighters, and stage. The config data you can leave null to use the default one for the project, but it can be overriden for specific game modes or stories or whatnot. Remember that you can define a config data based on another, as is done for the 2.5D / 2D game genre setup.

The exit part is actually done again in the battleinitdata: the exitcallback global BID holds a function reference that is called on match end with some parameters. The signature can be understood from the default one: DefaultExitCallback(stateHandle, _caller, _argument). As such, you have access to the state handle to get any data you want (eg score based on remaining HP), who called for the match to end (usually the winner), and an optional argument for extra info.

This should be flexible enough for most usecases. A concrete example:

  • In Kronian Titans, you select the opponent and weapon to use on the map, which sets up the match with the two mechs and sets up some variable overrides: HP, meter, distance from target.
  • Then you fight and when the game feels it’s enough, the match exits.
  • The tactical map reads back the HP and meter to update it in its own gamemode.

Do note that by default Castagne will recreate the assets and everything: reusing existing graphical scenes should be possible using a custom module and is much more dependant on your exact setup.

How do I trigger Castagne.InstanceCastagneEngine(battleInitData = null, configData = null) from within my specific scene. Tried to work it out on my own but I keep running into examples that aren’t actually what I’m doing and also for Godot 4. I’m learning Godot as I go along with this project.

Also not sure how to find the syntax to define the battleInitData when I do get the engine to instance.

This is one of the parts where Godot knowledge is mandatory, as it is about making the two systems interface. CastagneGlobal is a singleton, so you can call it from any function, in this case your story system. It returns a node ready to be used.

For the battle init data, the format is described in the docs iirc, and you can use the breakpoint to see the contents of the dict. One way can be to just copy that, or use the flow module or take inspiration from the menu code.

Since you’re a godot beginner, I would recommend working on your story system without worriying about castagne integration yet, just have a “start battle” function and an “end battle” callback you use as dummies before linking up Castagne proper.

Turns out I was triggering it right, I just got confused because I thought the ‘Unexpected assign’ error meant I did it wrong somehow, but turns out I should have just taken it at face value.

Looking through the docs and code has not been too helpful in figuring out how to manually set the BID, can’t even find a script where a print function will get it instead of complaining it isn’t declared in the scope. I know what the categories it expects are but not how to set it in a way that function will like and then do it for both players. Like my understanding is [“players”][0] would set the player to the fighter with id 0, but to do both players would it be [“players”][0,1]