Overlay displayed with experience gained (solved)

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.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Overlay displayed with experience gained (solved)

Post by Wussel »

I want to place an overlay according to the max experience an unit has. I was thinking of doing that inside the AMLA code, but it does not work. I could do it in an event firing every round, but than I would get a new overlay every round. It is NOT working and there is no error code. Any idea? Anything wrong? Something with the path to overlays? Right now I include the code as below in the AMLA code and expected it to fire, if an AMLA increases the max_experience to 12.

Code: Select all

       [effect]
		[if]
		[filter_wml]
			[variable]
                name=max_experience
                equal_to=12
            [/variable]
		[/filter_wml]
		[than]
			[unit_overlay]
				x,y=$x1,$y1
				image=overlays/exp-1.png
			[/unit_overlay]
		[/than]
		[/if]
        [/effect]		
 
Last edited by Wussel on June 14th, 2014, 5:35 pm, edited 1 time in total.
Vanagandr
Posts: 36
Joined: May 17th, 2014, 5:48 pm

Re: Overlay displayed with experience gained inside AMLA

Post by Vanagandr »

It is [then] and not [than], that will maybe fix it.
Edit: Also I think it should be

Code: Select all

[effect]
	[filter]
		[filter_wml]
			[variables]
				max_experience=12
			[/variables]
		[/filter_wml]
	[/filter]
	[unit_overlay]
		x,y=$x1,$y1
		image=overlays/exp-1.png
	[/unit_overlay]
[/effect]
instead of what you wrote.
Instead of the [unit_overlay] stuff you also need to use apply_to=overlay and so on as stated on the wiki.
Your Syntax is wrong in a lot of places, for example you can't use filters in [if], and [variable] is a condition tag and not the same as [variables] which you can use in filters.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Overlay displayed with experience gained inside AMLA

Post by zookeeper »

Wussel wrote:Anything wrong? Something with the path to overlays?
Everything about it is wrong. You really need to start from scratch with that one.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Overlay displayed with experience gained inside AMLA

Post by Dugi »

To describe it more precisely, you can't use AMLA for that. When a unit takes a new AMLA, only the effects of the latest AMLA are added and so the conditions for the previous [effect] tags aren't checked again. That is, any [effect]'s conditions will be applied accordingly to the situation that was at the time when it was added, not later. You can apply it at any time AMLA is applied, possibly as a part of AMLA, but that will cause the overlays to mass one on another (that will eventually start slowing the game down).

Another problem is the way you're adding the overlay. The [unit_overlay] tag will never work inside AMLA. You have to use an alternative, like [effect] with apply_to=image_mod and use the BLIT function in the image mod code.

To do it without possible nasty drawbacks, you should create an event that fires every time a unit advances,removes the old overlay (set_variables with split, check if the string contains something these experience overlays' names have in common), checks its maximum experience and gives it a new overlay accordingly. This event might be in every unit with AMLA, with an id assigned to prevent duplication.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Overlay displayed with experience gained inside AMLA

Post by Wussel »

Ok I get it. It will not work like this. The 2 fragments of code I used had been working in event_wml in the past. The amount of overlays will be just a few for different max_exp level. I was thinking of just stacking them.

How do I remove an overlay? You may asume, that I do know the name of the overlay. But there was something with containing some string? They are all called exp-X, where X is a number from 1 to 7.

Do I really have an event like every tun (beginn or end), check all units and give new overlays according to filter criteria? Then I would have to remove the old for sure since every units gets a new overlay every round. There was a level event, does this event apply to AMLA too???

Could you be more specific about how to code that?
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Overlay displayed with experience gained inside AMLA

Post by Dugi »

It can be a post advance event - a unit's maximum experience is unlikely to increase at different time.

Removing a specific overlay can be done like this (not assuring that this works, but I hope you'll get the idea and look up the details on the wiki):

Code: Select all

[store_unit]
 [filter]
  find_in=unit  # Replace this by your filter
 [/filter]
 variable=stored
[/store_unit]
[set_variables]
 name=overlays
 mode=replace
 [split]
  variable=stored.overlays
  separator=","
  key="overlay"
  remove_empty=yes
 [/split]
[/set_variables]
{FOREACH overlays i}
 [if]
  [variable]
   name=overlays[$i].overlay
   contains="exp" #This is the string to identify those you wanna remove
  [/variable]
  [then]
   {CLEAR_VARIABLE overlays[$i]}
   {VARIABLE_OP i sub 1}
  [/then]
 [/if]
{NEXT i}
[set_variable]
 name=stored.overlays
 [join]
  variable=overlays
  key=overlay
  separator=","
 [/join]
[/set_variables]
[unstore_unit]
 variable=stored
 find_vacant=no
[/unstore_unit]
Vanagandr
Posts: 36
Joined: May 17th, 2014, 5:48 pm

Re: Overlay displayed with experience gained inside AMLA

Post by Vanagandr »

You can remove an overlay with [remove_unit_overlay].
What exactly do you want to do? You can do it as part of your AMLA, but that makes it more difficult to remove overlays. If removing overlays is important you can do what Dugi suggested.
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: Overlay displayed with experience gained inside AMLA

Post by tekelili »

Vanagandr wrote:You can remove an overlay with [remove_unit_overlay]..
Yep, I am using succesfully a code as simple as this

Code: Select all

                [unit_overlay]
                    x,y=$x1,$y1
                    image= {IMG_IS_SPECIAL_OVERLAY}
                [/unit_overlay]

Code: Select all

                [remove_unit_overlay]
                    x,y=$x1,$y1
                    image= {IMG_IS_SPECIAL_OVERLAY}
                [/remove_unit_overlay]
for that very task ;)
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Overlay displayed with experience gained inside AMLA

Post by Wussel »

Code: Select all

#define EXP_MARKER
	[event]
		name=post_advance
		first_time_only=no
		[filter_wml]
			[variable]
                name=max_experience
                equal_to=12
            [/variable]
		[/filter_wml]
		[unit_overlay]
				x,y=$x1,$y1
				image=overlays/exp-1.png
		[/unit_overlay]
	[/event]
#enddef
Tried this one. It is working fine in sense that each amla triggers the overlay. Therefore the filter is not working. Since I would apply exp-2.png only if exp-1.png was already there a simple code might do. Is that the simple version?

Code: Select all

[remove_unit_overlay]
				x,y=$x1,$y1
				image=overlays/exp-1.png
		[/remove_unit_overlay]
lol you have beaten me on that. Thanks
Vanagandr
Posts: 36
Joined: May 17th, 2014, 5:48 pm

Re: Overlay displayed with experience gained inside AMLA

Post by Vanagandr »

As I wrote above, it should be

Code: Select all

[filter_wml]
       [variables]
             max_experience=12
       [/variables]
[/filter_wml]
[variable] cannot be used in filters, it is different from [variables] (what you want to use).
Edit: If you don't want to remove any existing overlays, then your code is fine (apart from the filter).
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Overlay displayed with experience gained inside AMLA

Post by Wussel »

Thanks for looking at my current challenge again. I did try your solution too, but it does not make any difference. The filter is just not working. Anybody any idea?
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: Overlay displayed with experience gained inside AMLA

Post by Wussel »

[variable]
Test the value of a WML variable against another value.
name: The name of the variable to test.
<comparison>: One of the following keys must be used to compare the value of the named variable, represented as $name below, against another value:
contains: $name contains this string value.
equals: $name is equal (string wise) to this value.
not_equals: $name is not equal (string wise) to this value.
numerical_equals: $name is equal (numerically) to this value.
numerical_not_equals: $name is not equal (numerically) to this value. *
* Using equals is faster. The point of numerical_equals and boolean_equals is not performance, it's representation. For instance, "1" and "1.0" are not equal as strings but they are equal as numbers; and "yes" and "true" are not equal as strings but they are equal as booleans. (This also explains why equals is faster: it is a straightforward comparison that doesn't try to understand what you have written.)
greater_than: $name is greater than this value.
greater_than_equal_to: $name is greater than or equal to this value.
less_than: $name is less than this value.
less_than_equal_to: $name is less than or equal to this value.
boolean_equals: $name has an equivalent boolean value. *
boolean_not_equals: $name does not have an equivalent boolean value. *
http://wiki.wesnoth.org/ConditionalActi ... ition_Tags

I found that interesting. It says: variable and numerical_equals.
No results anyway. Overlay allways gets displayed.

Update: Instead of filter_wml I tried if then else again. No results either.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Overlay displayed with experience gained inside AMLA

Post by zookeeper »

It's not working because it's all wrong. Look at EventWML.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Overlay displayed with experience gained inside AMLA

Post by Dugi »

Vanagandr wrote:

Code: Select all

[filter_wml]
       [variables]
             max_experience=12
       [/variables]
[/filter_wml]
This is totally wrong, by the way. It will check if there is a variable 'max_experience' saved inside the unit with value 12, not if the unit's max_experience is 12. Without the [variables] tag, it would check the unit's max_experience, but it would not allow comparing, only checking what is it equal to. Use the formula tag in StandardUnitFilter if you want to compare some variables in filters.

However, as I said, AMLA can't manipulate overlays. Use events for that. It doesn't matter if you use the code I showed you or remove_unit_overlay for all overlays you might possibly want to remove, but it must be in an event. Drop the idea of getting it to work with AMLA, that option is just not feasible.
Vanagandr
Posts: 36
Joined: May 17th, 2014, 5:48 pm

Re: Overlay displayed with experience gained inside AMLA

Post by Vanagandr »

Yeah, sorry I screwed that up, I was confused because he used [variable]. Just do

Code: Select all

[filter_wml]
	max_experience=12
[/filter_wml]
That will check if the unit's max XP is 12. As Dugi said [variables] is for variables of the unit that you set yourself.
You can manipulate overlays with [effect] (and therefore with AMLA) with apply_to=overlay. However that's not optimal if you want to remove the overlay later.
So

Code: Select all

#define EXP_MARKER
   [event]
      name=post_advance
      first_time_only=no
      [filter_wml]
	    max_experience=12
      [/filter_wml]
      [unit_overlay]
            x,y=$x1,$y1
            image=overlays/exp-1.png
      [/unit_overlay]
   [/event]
#enddef
should work I hope.
Post Reply