how can I make names for a specific unit type?

The place to post your WML questions and answers.

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.
User avatar
nobody5
Posts: 32
Joined: June 17th, 2009, 8:06 am
Location: The Oblivion

how can I make names for a specific unit type?

Post by nobody5 »

I was wondering can I make my own names that are automatically given to a unit type, regardless of it's race.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: how can I make names for a specific unit type?

Post by zookeeper »

nobody5 wrote:I was wondering can I make my own names that are automatically given to a unit type, regardless of it's race.
I'm guessing there's no other way than making a prerecruit unit type event which sets the name of the unit to whatever you want. However, even that won't help when you're just spawning [unit]s using random_traits=yes.
User avatar
nobody5
Posts: 32
Joined: June 17th, 2009, 8:06 am
Location: The Oblivion

Re: how can I make names for a specific unit type?

Post by nobody5 »

No, you didn't understand me. I wasn't talking about variations, I was talking about the unit's name (e.g. something like 'Gwedrry').
But if you really thought what I wrote above, then please explain it to me.

Here is an example of what I was thinking:

Let's say I want to give every Knight I recruit a a name such as "Sir Darren".
I make a name list. Then I do the rest. How?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: how can I make names for a specific unit type?

Post by zookeeper »

nobody5 wrote:No, you didn't understand me. I wasn't talking about variations, I was talking about the unit's name (e.g. something like 'Gwedrry').
But if you really thought what I wrote above, then please explain it to me.

Here is an example of what I was thinking:

Let's say I want to give every Knight I recruit a a name such as "Sir Darren".
I make a name list. Then I do the rest. How?
Yes, that's exactly what I was talking about.

If you want to use your own list of names:

Code: Select all

[event]
    name=prerecruit
    first_time_only=yes
    
    [filter]
        type=Knight
    [/filter]
    
    {RANDOM "Sir Darren,Sir Diesalot,Sir Bob"}
    
    {VARIABLE unit.name $random}
    
    [unstore_unit]
        variable=unit
        find_vacant=no
    [/unstore_unit]
[/event]
Or if you want to use the existing random names and just prefix them with "Sir":

Code: Select all

[event]
    name=prerecruit
    first_time_only=yes
    
    [filter]
        type=Knight
    [/filter]
    
    {VARIABLE unit.name "Sir $unit.name"}
    
    [unstore_unit]
        variable=unit
        find_vacant=no
    [/unstore_unit]
[/event]
And [event]s go where [event]s go.
User avatar
nobody5
Posts: 32
Joined: June 17th, 2009, 8:06 am
Location: The Oblivion

Re: how can I make names for a specific unit type?

Post by nobody5 »

Thanks, you helped a lot. It doesn't seem so hard after all.
By the way, if I wanted a "sir" title to append to the name on advancement,
I would write:

Code: Select all

    [event]
	name=post_advance
	first_time_only=no
   
	[filter]
            type=Knight_dismounted
	[/filter]
   
	{VARIABLE unit.name "Sir $unit.name"}
   
	[unstore_unit]
            variable=unit
            find_vacant=no
	[/unstore_unit]
    [/event]
Is that right?
Note: I think 'first_time_only' should be no, because I want it to happen every time
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: how can I make names for a specific unit type?

Post by A Guy »

Yes, that is right. You don't need to specify find_vacant because it's no by default.
I'm just... a guy...
I'm back for now, I might get started on some work again.
AssassinT90
Posts: 39
Joined: December 20th, 2007, 9:47 am

Re: how can I make names for a specific unit type?

Post by AssassinT90 »

Code: Select all

[unstore_unit]
        variable=unit
        find_vacant=no
[/unstore_unit]
I'm wondering about why that is code useful. Already read its([unstore_unit]) effect, but couldn't understand well. Could somebody make it clear?
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: how can I make names for a specific unit type?

Post by melinath »

I would give you a link to a thread that shows how it's useful, but you posted in one. I assume you already looked at the examples here. Could you be more specific what you don't understand?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: how can I make names for a specific unit type?

Post by zookeeper »

AssassinT90 wrote:

Code: Select all

[unstore_unit]
        variable=unit
        find_vacant=no
[/unstore_unit]
I'm wondering about why that is code useful. Already read its([unstore_unit]) effect, but couldn't understand well. Could somebody make it clear?
One way to modify an existing unit is to use an [object]. The other one, used here, is to directly edit its properties. All units are stored as WML, as tags and keys. You can open an (uncompressed) savefile and check; it's all WML, nothing more.

So, usually you use [store_unit] to store some existing unit into a variable, then change that variable, and finally use [unstore_unit] to make the game create an actual existing unit from the contents of that variable. In this case, [store_unit] isn't used because by default the primary unit associated with an event is stored in the variable called "unit".

What {VARIABLE unit.name "Sir $unit.name"} does is tells the game to replace the contents of the variable unit.name with the value of that variable preceded with "Sir ". After that, the unit data stored in the variable "unit" is identical to that of the actual unit whose advancement triggered that event except that it now has a different name. Then, [unstore_unit] tells the game to take the contents of that variable and create an actual unit on the map from it - which leads to the original unit getting eliminated because the "new" unit appears on top of it because it has the same x and y coordinates (if find_vacant=yes would be used, the "new" one would appear in an adjacent hex instead, leading to two copies of the unit on the map, only with different names).

If you'd remove the [unstore_unit], then nothing would happen, as you would have simply modified a variable and the game doesn't by itself do anything with any variable unless you tell it to.
AssassinT90
Posts: 39
Joined: December 20th, 2007, 9:47 am

Re: how can I make names for a specific unit type?

Post by AssassinT90 »

@zookeeper, melinath:
Thank you(again)!
User avatar
nobody5
Posts: 32
Joined: June 17th, 2009, 8:06 am
Location: The Oblivion

Re: how can I make names for a specific unit type?

Post by nobody5 »

You know, that post_advance event doesn't work. Why? It's totally logical:

Code: Select all

    [event]
        name=post_advance
        first_time_only=no
   
        [filter]
            type=Horseman
        [/filter]
   
        {VARIABLE unit.name "Sir $unit.name"}
   
        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]
    [/event]
This would trigger when a horseman advances, but it doesn't add the 'Sir' title.
And if I use advance, then it creates weird infinite advancement that adds 'Sir' a million times.
User avatar
Turuk
Sithslayer
Posts: 5283
Joined: February 28th, 2007, 8:58 pm
Contact:

Re: how can I make names for a specific unit type?

Post by Turuk »

nobody5 wrote:This would trigger when a horseman advances, but it doesn't add the 'Sir' title.
And if I use advance, then it creates weird infinite advancement that adds 'Sir' a million times.
You wrote:
nobody5 wrote:Is that right?
Note: I think 'first_time_only' should be no, because I want it to happen every time
Everyone else wrote:

Code: Select all

first_time_only=yes
Mainline Maintainer: AOI, DM, NR, TB and THoT.
UMC Maintainer: Forward They Cried, A Few Logs, A Few More Logs, Start of the War, and Battle Against Time
User avatar
nobody5
Posts: 32
Joined: June 17th, 2009, 8:06 am
Location: The Oblivion

Re: how can I make names for a specific unit type?

Post by nobody5 »

Now it works, but it happens only the first time! I want it to happen always!
The code:

Code: Select all

    [event]
        name=advance
        first_time_only=yes
   
        [filter]
            type=Horseman
        [/filter]
   
        {VARIABLE unit.name "Sir $unit.name"}
   
        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]
    [/event]
Help meeeeeee!!!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: how can I make names for a specific unit type?

Post by zookeeper »

nobody5 wrote:You know, that post_advance event doesn't work. Why? It's totally logical:

Code: Select all

    [event]
        name=post_advance
        first_time_only=no
   
        [filter]
            type=Horseman
        [/filter]
   
        {VARIABLE unit.name "Sir $unit.name"}
   
        [unstore_unit]
            variable=unit
            find_vacant=no
        [/unstore_unit]
    [/event]
This would trigger when a horseman advances, but it doesn't add the 'Sir' title.
Probably the filter applies to the unit after advancement, so if you want "Sir" to be added when advancing to a Knight, don't use type=Horseman as the filter, but type=Knight.
nobody5 wrote:And if I use advance, then it creates weird infinite advancement that adds 'Sir' a million times.
Yeah, that seems to be a strange bug.
User avatar
nobody5
Posts: 32
Joined: June 17th, 2009, 8:06 am
Location: The Oblivion

Re: how can I make names for a specific unit type?

Post by nobody5 »

Nay, it has to be Horseman, otherwise nothing happens, except when a Knight advances. And who wants to bother with adding a advancing event for Knight, it already gets 'Sir' when it's recruited, so I'll get 'Sir Sir Bob'!
Post Reply