name_generator query
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
- Spannerbag
- Posts: 759
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
name_generator query
First, apologies if I've posted in the wrong place; I'm assuming what I'd like to do is possible in WML. 
Is it possible to create a WML wrapper around name_generator so that the output can be captured in a WML variable?
I'd like to rename a unit when it advances via an
Ideally I'd like to:
I'd rather not spawn a new unit purely for purposes of acquiring its name because this event fires when the unit advances and could possibly fire in one of several scenarios with different maps etc., so things get fiddly.
Alternatively can use lua if that's easier, but would prefer a WML solution.
All advice and suggestions gratefully received!
Cheers!
-- Spannerbag

Is it possible to create a WML wrapper around name_generator so that the output can be captured in a WML variable?
I'd like to rename a unit when it advances via an
[event]
within the [unit_type]
.Ideally I'd like to:
- Save the old name (in say
$unitname_old
). - Generate a new name (
$unitname_new
*). - Rename the unit to:
"$unitname_new
" + " " + "$unitname_old
" + "_" + "Rider".
short_name={prefix}{suffix}
}) Dwarvish name.I'd rather not spawn a new unit purely for purposes of acquiring its name because this event fires when the unit advances and could possibly fire in one of several scenarios with different maps etc., so things get fiddly.
Alternatively can use lua if that's easier, but would prefer a WML solution.
All advice and suggestions gratefully received!
Cheers!
-- Spannerbag
Re: name_generator query
Easiest way would be to register new WML tag that does what you need with Lua.
Consider that old name might not be from generator.
Consider that old name might not be from generator.
- Spannerbag
- Posts: 759
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: name_generator query
Mmm.. given my minimal lua ability this is drifting into "not worth the effort" territory...
Will play around with easier/simpler alternatives first and see how I get on.
Good point.
Thanks for your post, it clarified my options, thanks.
Cheers!
-- Spannerbag
Re: name_generator query
If your problem is not wanting to spawn units on top of other ones, you can spawn one directly into the recall list.
Here is a macro that does what you want, I think (this one is inside a move-to event).
Did your unit get climbed on by a dwarf...?
As for generating a short_name specifically, you could make a custom unit and link it to an edited name generator.
Here is the DWARVISH_NAMES macro with long_name, centre and markov section removed:
edit: If I were using this, I would prune the generator a little. I see the possible names "Doing" "Timing" and "Aas".
Here is a macro that does what you want, I think (this one is inside a move-to event).
Code: Select all
#define GAIN_A_NAME
[label]
x,y=5,5
text="<span color='#76AA2F' size='x-small' weight='normal'>" + _ "Rename unit here" + "</span>"
[/label]
[event]
name=moveto
[filter]
side=1
x,y=5,5
[/filter]
first_time_only=no
[unit]
side=1
type="Dwarvish Ulfserker"
x=recall
y=recall
id=NamePatsy
generate_name=yes
[/unit]
[store_unit]
[filter]
id=NamePatsy
[/filter]
variable=stored_patsy
[/store_unit]
[set_variable]
name=patsy_name
value= $stored_patsy.name
[/set_variable]
[unstore_unit]
variable=stored_patsy
[/unstore_unit]
[kill]
id=NamePatsy
[/kill]
[set_variable]
name=old_name
value= $unit.name
[/set_variable]
[set_variable]
name=new_name
value=$patsy_name| + " " + $old_name| + "-Rider" # "|" necessary for separating variables, I think
[/set_variable]
[modify_unit]
[filter]
x,y = $x1, $y1
[/filter]
name=$new_name
[/modify_unit]
[/event]
#enddef
As for generating a short_name specifically, you could make a custom unit and link it to an edited name generator.
Here is the DWARVISH_NAMES macro with long_name, centre and markov section removed:
Code: Select all
#define SHORT_DWARVISH_NAMES
# po: Generator for male dwarf names; see <https://wiki.wesnoth.org/Context-free_grammar> for syntax
name_generator= _ <<
main={short_name}
short_name={prefix}{suffix}
prefix=Ai|Al|A|Du|Glam|Dul|Gom|Nar|Pel|Tri|Dun|Do|Bar|Er|Tim|Al|Du|Bu|Bur|Nor|Der|Ur|Gar
suffix=sil|fur|bor|bus|bur|bor|gos|dor|rin|dur|ing|ras|this|tis|rol|sol|las|til|til|tol|los|rol|sol|ril|sil|as|us|lil|fur|mur|fur
>>
#enddef
- Spannerbag
- Posts: 759
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: name_generator query
Thanks for your post; it helps - but you underestimate my ignorance!

I did consider creating to recall and understand (I think) how to configure the generator to create short names but this still left the issue of "deploying" this logic for generating a short name; i.e. how to tell
[unit]
to use the customised generator.Specifically, the bits of knowledge I'm lacking are how to either:
- Capture the generator's output into a variable, or
- How to invoke/use the customised version of the generator rather than the standard one.
I'm working on other bits and bobs as time permits and will probably bodge write a home brewed custom short name generator in WML if need be.
However this feature is a "nice to have" rather than "essential" so I'm presently simply hard coding the names (i.e. they are always the same).
So please don't spend ages on this, it really isn't that important!

Again, thanks for your post, much appreciated.
Cheers!
-- Spannerbag
Re: name_generator query
Don't worry, since I have made name generators before, this work-around was very quick to finish. I just copy-paste and delete a lot. Although, I will tell you that I do not know anything about LUA (option a). So maybe there is a better solution there.
For option b:
In short: name generator -> race -> units
So you need a custom race to call your custom name generator.
Longer:
First of all, I think it is not possible to create a short name using the original DWARVISH_NAMES. The generator always returns "main" and main returns "long_name". "short_name" is perhaps legacy code.
Anyway, I have put the SHORT_DWARVISH_NAMES inside the file /utils/names.cfg
Then I put this race definition inside of /utils/units.cfg
I believe this is the minimum race info to avoid error messages.
Then, in /units/namedummy.cfg, this unit:
Then in the macro from before, replaced "Dwarvish Ulfserker" with "Name Dummy".
Here is the result:
This is not quite what you wanted, anyway, but hopefully it gives you enough information to create your solution
-
For option b:
In short: name generator -> race -> units
So you need a custom race to call your custom name generator.
Longer:
First of all, I think it is not possible to create a short name using the original DWARVISH_NAMES. The generator always returns "main" and main returns "long_name". "short_name" is perhaps legacy code.
Anyway, I have put the SHORT_DWARVISH_NAMES inside the file /utils/names.cfg
Then I put this race definition inside of /utils/units.cfg
I believe this is the minimum race info to avoid error messages.
Code: Select all
[units]
{~add-ons/fire/units}
[race]
id=shortnameddwarves
name= _ "race^Short named dwarf"
plural_name= _ "race^Short named dwarves"
{SHORT_DWARVISH_NAMES}
[/race]
[/units]
Code: Select all
[unit_type]
id=Name Dummy
name= _ "Name Dummy"
race=shortnameddwarves
image="units/name-dummy.png"
hitpoints=1
level=1
description= _ "Placeholder description. This is a dummy unit. If it appears, it is an error."
[/unit_type]
Here is the result:
This is not quite what you wanted, anyway, but hopefully it gives you enough information to create your solution

-
- Spannerbag
- Posts: 759
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: name_generator query
Phew.
Thanks, very helpful and enlightening, much appreciated!
Will experiment with your code, thanks again for your time and trouble!
Cheer!
-- Spannerbag