Changing the image of a unit

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
Ptitboul
Posts: 73
Joined: May 8th, 2021, 3:45 pm

Changing the image of a unit

Post by Ptitboul »

With Wesnoth 1.12, this can simply be done by changing the value of $unit.image.

But with Westnoth 1.14.16 the behaviour is different: whatever the value of the "image" key in the description of the unit, the one which is displayed is the one from the definition of the unit type. This is true even when changing the content of the save file.
I don't understand why this change of behaviour (why keep the "image" key in the unit if it is not used), and I don't know how to circumvent it.
My campaign, Bloodlust, is is need of feedback!
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Changing the image of a unit

Post by beetlenaut »

The current animation system is much more powerful than it was in the past, so it is more complicated as well. (The image tag seems to be used to build the default animations when the unit is loaded for the first time. Someone can correct me if that's wrong.)

The only way to change the image of a unit after it is loaded is to pass it an object that adds an animation. (See EffectWML for more information.) Adding a single-frame standing animation should change the base image. However, if the unit already had a standing animation, I think you will have to add some filters or a base_score to make sure your new standing animation is chosen over the old one every time--otherwise it will be random. (AnimationWML has details on that.)

If it's possible in your case, it would probably be easier to change the unit_type so that it is reloaded. You can use [base_unit] to make a clone of another unit with nothing but the image changed.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Changing the image of a unit

Post by Ravana »

I have changed image by adding image mod "O(0) followed by BLIT. It seems to still work in 1.15.15.
Ptitboul
Posts: 73
Joined: May 8th, 2021, 3:45 pm

Re: Changing the image of a unit

Post by Ptitboul »

Thank you for the answers.
I want to have a unit_type with no image, and the image dynamically changed when some AMLA have been taken.

You gave me two techniques that could allow me to reach this goal.
If it does not work, I will come again to ask additional questions.
If it works, I will come back to thank you again!
My campaign, Bloodlust, is is need of feedback!
Ptitboul
Posts: 73
Joined: May 8th, 2021, 3:45 pm

Re: Changing the image of a unit

Post by Ptitboul »

Code: Select all

                    [effect]
                        apply_to=image_mod
                        replace="~O(0)~BLIT($temp.image)"
                    [/effect]
works for me, under the condition that the unit_type defines an image (which will be overwritten).
If the unit_type does not define any image, then the image_mod has apparently no effect.
My campaign, Bloodlust, is is need of feedback!
Post Reply