1) When writing up the reaction, what do I need to write in the product to make it run the script? I already have the reagent and workshop specified. I tried to look at an example reaction that uses a script but I couldn't find the part where the reaction said "use x script" which is what I need.
2) Do I actually need to write anything in the product for this reaction? Products have always kind of tripped me up when writing reactions, so any help is appreciated. If so, what?
3) How do I connect the reaction to the script?
4) Is there any known worldgen weirdness involving races that exclusively use reactions to reproduce? Including ones that need the create-unit lua script like above?
1) You don't have to write anything special in the reaction itself (see later points). I think there was/still is functionality to do it by naming reactions in certain ways, but I don't know if anyone still does that.
2) IIRC yes, the reaction needs a product, or else the code doesn't actually trigger (even though the documentation says otherwise). There's supposed to be a way to prevent the product from actually being made, but I believe that functionality is broken/removed (though I could be misremembering, it's been ages), so most people set the product to be a boulder of a dummy material that turns into gas instantly.
3) By using
modtools/reaction-trigger. You should include each command inside an
onLoad init file, so they get automatically run every time a world is loaded (otherwise you'd have to manually type in each command into the console every time you load up the world
).
Here's an example from an old mod I abandoned. When the reaction with the ID "THE_HIVE_SPAWN_QUEEN" is completed, a QUEEN caste of the creature THE_HIVE is spawned that's part of the fort, and uses THE_HIVE entity's naming conventions:
modtools/reaction-trigger -reactionName THE_HIVE_SPAWN_QUEEN -command [ modtools/create-unit -race THE_HIVE -caste QUEEN -setUnitToFort -name THE_HIVE -location [ \\LOCATION ] -age 0 ]
4) If I remember correctly, there will be problems in worldgen for creatures that reproduce solely from reactions. create-unit combined with reaction-trigger only spawns the creatures from their reactions
when the reaction is used during fortress mode. This means that for all of worldgen, no new creatures are actually spawned, and so that civilisation is left with just their default level of population that the game initially spawns them with (assuming they can't reproduce on their own).
It
might be possible to rig something up to have them create more of themselves during worldgen, like say giving them a dummy item that they can create as a craft, and then periodically replacing any of those items stored in a site with people instead. It'd obviously need a custom made script for it (I don't think one such script exists currently), and I'm not sure how possible it is, since I've never touched anything worldgen related before. 🤔
Given your content, whether it still works needs to be seen but "construct-creature.lua by IndigoPhoenix" might fit your purposes because of the way it transfers the reagent material directly into it.
That does look pretty old, and I'm not sure how well it'll work, but I'm glad I stumbled upon it. I never realised/considered you could just straight-up edit the materials a creature is made up from. I was considering potentially picking up one of my old mod concepts that involves creating golems, and I was going to just cheat making them out of a particular material by colouring their body material based on the colour of the material used, but actually making them out of their material sounds better.
Though actually looking into it, it doesn't look like those changes to a unit's materials are actually saved, so you'd have to reapply them whenever they're loaded, which seems like potentially more effort than it's worth.