Total War: WARHAMMER III

Total War: WARHAMMER III

Variant Selector
Marthenil  [developer] 13 Apr, 2023 @ 6:52pm
Community functionality
Discussions about community functions etc go here
< >
Showing 1-10 of 10 comments
LazyIcarus 27 Nov, 2022 @ 4:34pm 
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  [developer] 28 Nov, 2022 @ 1:01am 
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 @ 5:27pm 
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  [developer] 28 Nov, 2022 @ 5:54pm 
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.
Last edited by Marthenil; 28 Nov, 2022 @ 5:56pm
LazyIcarus 28 Nov, 2022 @ 8:29pm 
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  [developer] 13 Apr, 2023 @ 12:29pm 
Kinda late but this is now a thing.
LazyIcarus 13 Apr, 2023 @ 1:37pm 
Nice, will take a look into the new code to see how to make my stuff compatible
LazyIcarus 13 Apr, 2023 @ 4:24pm 
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  [developer] 13 Apr, 2023 @ 6:48pm 
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.
Last edited by Marthenil; 13 Apr, 2023 @ 7:06pm
Marthenil  [developer] 14 Apr, 2023 @ 8:09am 
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)
< >
Showing 1-10 of 10 comments
Per page: 1530 50