How to make a unit do a thing in X turns

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.
Post Reply
Contaron
Posts: 3
Joined: March 10th, 2021, 5:12 pm

How to make a unit do a thing in X turns

Post by Contaron »

I am making a unit that transforms into a different unit depending on the terrain after a few turns.

I believe I can simply use an event to transform the unit with a bunch of if tags to decide what it gets turned into. However, I don't know how to actually trigger this event. I want it to be that 3 turns after my unit spawns, it transforms. The unit is immobile (we have a cocoon type thing going on here).

How could I make this work?
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: How to make a unit do a thing in X turns

Post by vghetto »

You need to be more specific in describing what you want.
All I can say for now is have look at Liberty's 4th scenario for reference.

As for making a unit do a thing in X turns, you have 2 options. Either inject an event when you create the unit and have it be $($turn_number + 3) or use [unit] [variables] to set up a counter and increment that after each turn.
Contaron
Posts: 3
Joined: March 10th, 2021, 5:12 pm

Re: How to make a unit do a thing in X turns

Post by Contaron »

To be more specific, I am making a unit type that is spawned from other units (this bit works). I want each iteration of the unit to transform after that specific iteration has been alive for 3 turns. What do I put in the unit type WML to trigger the transformation?
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: How to make a unit do a thing in X turns

Post by vghetto »

Inside the unit_type you can add something like this:

Code: Select all

        [event]
            name=unit placed
            [event]
                name=turn_"$($turn_number + 3)"
                delayed_variable_substitution=no

                # Do Stuff
            [/event]
        [/event]
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: How to make a unit do a thing in X turns

Post by vghetto »

Here is a more fleshed out example, I recommend using a custom event name and firing that when you place the unit instead of relying on "unit placed"

In this example the recruited custom peasant unit dies after 3 turns

Code: Select all

    [unit_type]
        [base_unit]
            id=Peasant
        [/base_unit]
        id=My_Peasant
        hide_help=yes
        do_not_list=yes
        [event]
            name=unit_placed,my_custom_event_name
            first_time_only=no
            [filter]
                type=My_Peasant
            [/filter]
            [event]
                name=turn_"$($turn_number + 3)"
                delayed_variable_substitution=no
                [kill]
                    id=$unit.id
                [/kill]
            [/event]
        [/event]
    [/unit_type]
Contaron
Posts: 3
Joined: March 10th, 2021, 5:12 pm

Re: How to make a unit do a thing in X turns

Post by Contaron »

That is marvellously helpful, thank you.
Post Reply