Total War: WARHAMMER III

Total War: WARHAMMER III

Variant Selector
Marthenil  [udvikler] 13. apr. 2023 kl. 18:52
Community functionality
Discussions about community functions etc go here
< >
Viser 1-10 af 10 kommentarer
LazyIcarus 27. nov. 2022 kl. 16:34 
Hi, I have mods that dynamically adjust the art set and I'd like it so that variant selector only shows amongst all the variants unlocked so far. I've implemented this by exposing two global functions. Could you please add this to the main mod so I don't have to maintain a fork of this mod? This would also enable a more transparent way of adding variants since they run actual code rather than returning a table from a file.

---Global function to allow dynamically changing variant options ---@param character_subtype_key string ---@param art_set_ids table Table with numerical keys each mapping to an art set ID function Set_character_variants(character_subtype_key, art_set_ids) variants_table[character_subtype_key] = art_set_ids; -- no need to rebuild anything since the UI components are generated only when opened end ---Global function to alert variant selector that a variant for a character has been changed by an external source, ---presumably the same source that called Set_character_variants since they need to know what each index corresponds to ---@param character_cqi integer|string ---@param variant_index integer function Has_set_character_variant(character_cqi, variant_index) character_variant_index[tostring(character_cqi)] = variant_index; end
Marthenil  [udvikler] 28. nov. 2022 kl. 1:01 
I was already passing setfenv to the loaded files so you can load code in them as well (well, technically you already can, just no game functions) next update, but yeah more control is better, I'll add something like that too.
LazyIcarus 28. nov. 2022 kl. 17:27 
Not too familiar with lua so not sure if passing setfenv is sufficient for what my mods need. They listen for in game events to unlock and switch to variants. For example, waits for turn 15 to pass. This is what I meant by "dynamically" - during the course of a play session rather than variants loaded upon loading the game.
Marthenil  [udvikler] 28. nov. 2022 kl. 17:54 
Basically using setfenv (and passing the game environment to the loaded chunk) would make Variant Selector files pretty much equivalent to any old lua file loaded through "script/campaign/mod".They already are perfectly valid lua chunks but because they don't get the function environment you can't call game functions within them, just basic lua stuff.

It wouldn't be sufficient for your purpose though (at least as is) cause the return is only read once.
Still, it's useful for other cases, say you can read if a mod is installed and if that's true return X variant table or else return Y variant table.
Sidst redigeret af Marthenil; 28. nov. 2022 kl. 17:56
LazyIcarus 28. nov. 2022 kl. 20:29 
I see... That's a bit low level and dependent on mod load order right? Your mod would have to be loaded after the mods you want to check if they're installed. Glad to hear it'll be added in the next update. Please allow assigning entire art set tables for character subtypes like I've proposed above, rather than going for an incremental "update" and "remove" API. I need to manage which of the variants' been unlocked and variant selector is only an optional dependency so it can't be the only source of truth for it.
Marthenil  [udvikler] 13. apr. 2023 kl. 12:29 
Kinda late but this is now a thing.
LazyIcarus 13. apr. 2023 kl. 13:37 
Nice, will take a look into the new code to see how to make my stuff compatible
LazyIcarus 13. apr. 2023 kl. 16:24 
Is it possible to capitalize the first letter of these global functions? I think the general convention is to have capitalized first letter snake case for global functions and snake case for local functions (as you current have)
Marthenil  [udvikler] 13. apr. 2023 kl. 18:48 
No, CA formatting is all snakecase with no capitals, even for globals, imma keep it like that. HOWEVER, I should probably make the global a single object that contains all the functions, instead.

And done.
Sidst redigeret af Marthenil; 13. apr. 2023 kl. 19:06
Marthenil  [udvikler] 14. apr. 2023 kl. 8:09 
Alright alright alright, this is the final update for these functions. From now on they are set in stone and I'm not touching their names or functionality again. (I might do some type-checking and error reporting later)
< >
Viser 1-10 af 10 kommentarer
Per side: 1530 50