How to modularize and pass variables between Simulations

We are currently using Gatling to mimic the behavior of a complex system, which includes setup, triggering batch process, and running a bunch of simulations in parallel. All of them from a single entry-point. Facing difficulty in breaking down the steps into modules, with passing values between them.

For example: Let’s assume the following structure. (All actions are HTTP endpoints)

Create One Parent:(returns parentToken) Create up to 3 Children:(uses ParentToken and creates ChildToken) create multiple Resources based on parentToken and one of the childToken randomly chosen.

We are using Sequential Simulations to order the events. Currently, we are using mutable variables in scala (either single value or collection) to save values from one simulation and make it available for simulation. If there is a chain of Simulations, then we can just use check() to save to session and read from the session.

Apologies if the question is unclear, will review this question again. Any pointer to how modularization is achieved in Gatling will be helpful.

(Ideally Functional decomposition, Step1[A,B] → Step2[B,C] → flatMap ((b,c)-> Step3[B,C]))