enclave's WML Macros questions Thread

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
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Hi, regarding user interface..
I was trying to figure out how to use [theme], but looks like I don't know..
I tried to just stupidly copy whole theme.cfg from another era.. and nothing worked..
In between which tags [theme] should be located? it says toplevel.. which means?
And is it possible to change just only 1 image of top bar? Without affecting anything else?
I mean for example:

Code: Select all

[theme]
[label]
            id=income-icon
            icon=themes/bullion-income.png
            text= _ "income"
            ref=income-box-center
            rect="=+1,=-1,+25,+17"
            xanchor=fixed
            yanchor=fixed
        [/label]
[/theme]
would it work this way?
Thanks!

PS. would it work with existing images? not from add-on/themes folder? but from the core? like icons/sandals.png?
would it require add-on download to play? (1.12)
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Hi everyone..

I have the following problem:
When I watch reloaded games of my mod from server ( http://replays.wesnoth.org/1.12/ )
they are always corrupted (full of oos)
I don't know why, and maybe I gave up long time ago on the reasons, but what I really would like to know at the moment is,
can a reload replay be fixed? What exactly needs to be modified to fix a reloaded game?
I have uploaded an example (no add-on needed), it gives me oos.
Anyone who knows how, please give me a hint or something (maybe a quick example of a short code of before fix and after fix)..
Thank you very much!

PS. im on wesnoth 1.12.2 (currently uploaded replay is 1.12.5, not sure if it matters as when I watch normal games of my mod (not reloaded) there is never any OOS problem)
Attachments
NS_Random_Survival_OT_x3_Turn_24_(53672).bz2
reloaded game from turn 19 to 24
(398.01 KiB) Downloaded 335 times
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

I have decided to add sounds to my add-on.. yeah a bit strange timing.. it was without sounds for all this time.. and I wasn't interested because I play wesnoth without speakers or earphones.. music etc.. but makes sense to add sounds.. for others.
From what I remember is that when sound was used in popup menu, the enemy could hear the "not enough money" sound.. which was a bit silly.. And i looked into wiki.. [sound] doesn't have a side_for= ...

so here is my question:
If I use sound on some action taking place in coordinates x,y.. Will everyone in game hear it? Or only players that don't have fog or shroud in that x,y place? I wouldn't want to trash the game with sounds for people who are not anyhow related to it.. So in my opinion its better leave game muted than to allow player 1 hear some action taking place in the opposite corner of the map of player 2... I'm actually shocked that [sound] has no side_for !?!?
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Sorry, I found the proper way to write the code I was asking below, I'm not 100% happy, but it works..
Spoiler:
Hi everyone,
Curious question about filters.. version 1.12

I have an event moveto
I have 2 problems with it.. and 4 different ways of writing it, none of them making me happy.. way #5 would be an overkill.. of common sense... there is also 6th way.. but its also bad..

To make me happy the event needs to meet 2 criterias:
1) not to interrupt movement of a unit sent to attack another unit..
2) just work..

Ok.. first I will show the way that it works perfectly:

Code: Select all

[event]
	name=moveto
	first_time_only=no
	[filter]
		side=$side_number
		x,y=$x1,$y1
		[filter_wml]
			[variables]
				range=2
			[/variables]
			[not]
				attacks_left=0
			[/not]
		[/filter_wml]
	[/filter]
	[select_unit]
		x,y=$x1,$y1
		fire_event=yes
	[/select_unit]
[/event]
But the problem is that I want it to work if variables range is between 2 and 10.. not just only 2.. and it just refuses to do it..

Way #1 filter does not work..

Code: Select all

[event]
	name=moveto
	first_time_only=no
	[filter]
		side=$side_number
		x,y=$x1,$y1
		[filter_wml]
			[variables]
				range=2
			[/variables]
			[or]
			[variables]
				range=3
			[/variables]
			[/or]
			[not]
				attacks_left=0
			[/not]
		[/filter_wml]
	[/filter]
	[select_unit]
		x,y=$x1,$y1
		fire_event=yes
	[/select_unit]
[/event]
way #2 filter does not work

Code: Select all

[event]
	name=moveto
	first_time_only=no
	[filter]
		side=$side_number
		x,y=$x1,$y1
		[filter_wml]
			[variables]
				range=2,3,4,5,6,7,8,9,10
			[/variables]
			[not]
				attacks_left=0
			[/not]
		[/filter_wml]
	[/filter]
	[select_unit]
		x,y=$x1,$y1
		fire_event=yes
	[/select_unit]
[/event]
way #3 filter does not work

Code: Select all

[event]
	name=moveto
	first_time_only=no
	[filter]
		side=$side_number
		x,y=$x1,$y1
		[filter_wml]
			[variables]
				range=2..10
			[/variables]
			[not]
				attacks_left=0
			[/not]
		[/filter_wml]
	[/filter]
	[select_unit]
		x,y=$x1,$y1
		fire_event=yes
	[/select_unit]
[/event]
way #4 filter works but it causes unit to stop moving and need to select it again to attack.. (interrupts movement)

Code: Select all

[event]
	name=moveto
	first_time_only=no
	[filter]
		side=$side_number
		x,y=$x1,$y1
		[filter_wml]
			[not]
				attacks_left=0
			[/not]
		[/filter_wml]
		[filter_condition]
			[variable]
				name=unit.variables.range
				greater_than=1
			[/variable]
		[/filter_condition]
	[/filter]
	[select_unit]
		x,y=$x1,$y1
		fire_event=yes
	[/select_unit]
[/event]
way #5 just to copy paste the event 10 times with 2, then 3, then 4 etc.. really? :(

way #6 to add [allow_undo][/allow_undo] into way #4 (causes lua error if undo is performed, because I have select event that is influencing the game via wesnoth.synchronize_choice)

I dont understand why 2,3,4,5,6,7,8,9,10 or 2..10 or [or][/or] don't work?.. is it something typical/normal or not? maybe I'm missing something.. Thanks very much in advance..
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: enclave's WML Macros questions Thread

Post by Sapient »

enclave wrote:

Code: Select all

	side=$side_number
	x,y=$x1,$y1
1. Question: Why are you filtering side=$side_number and x,y=$x1,$y1 ?
Answer: There is no need to.
The filter for a moveto event is only tested against the unit that moved.
So that test is completely redundant.
enclave wrote: I dont understand why 2,3,4,5,6,7,8,9,10 or 2..10 or [or][/or] don't work?
2. Question: When you read the documentation for [filter_wml], where does it say that it supports [or] ? where does it say that it supports numeric ranges?

Answer: it does not.
In truth, it shouldn't support [not] either. But I guess that's water under the bridge now.

Reason: [filter_wml] is supposed to do a tag-for-tag, word-for-word match*.
This allows you to test whether any tag actually exists inside the unit variable, even tags with special names like [or]. And it allows you to find values like favorite_convenience_store="7-11", which it wouldn't be able to find if we went with your supposed range-matching syntax.

* I didn't say "literal" match, because things like variables and [insert_tag] are still interpreted.

enclave wrote: maybe I'm missing something..
You should use [filter_condition] to perform [variable] tests on $unit.variables.whatever

Code: Select all

[filter_condition]
  [variable]
    name=unit.variables.range
    greater_than=1
  [/variable]
  [variable]
    name=unit.variables.range
    less_than=11
  [/variable]
  [variable]
    name=unit.attacks_left
    greater_than=0
  [/variable]
[/filter_condition]
It's also possible to do this in other ways, such as with formula language, although not as simple.

Code: Select all

[filter]
  formula="attacks_left>0 and range>1 and range<11 where range=$unit.variables.range-0"
  # subtract zero to create a default range of 0 if range is not defined
[/filter]
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Thank you very much Sapient for your long and detailed answer, I really appreciate your time!

About your question 1: I didn't know that filter for moveto is filtering $x1,$y1 automatically. But i use side=$side_number because I have some kind of graphical thing which I want to be visible only to side moving the unit and not all sides.. from your answer I assume now that it also filters $side_number automatically, but with all respect, I somehow don't believe it :) even knowing im 90% wrong to not believe you on this.. it would be strange if it works that way.

Question 2: just what I needed to know;) Not supposed to work that way ;) Thanks!
Sapient wrote:You should use [filter_condition] to perform [variable] tests on $unit.variables.whatever
Just like I wrote in my post, I can not use filter_condition because for some magical reason [filter_condition] makes my units stop before attacking unlike [filter_wml]. But thanks for example of formula filtering, I don't think I could find one anywhere!!!
User avatar
beetlenaut
Developer
Posts: 2813
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: enclave's WML Macros questions Thread

Post by beetlenaut »

enclave wrote:I didn't know that filter for moveto is filtering $x1,$y1 automatically. But i use side=$side_number because I have some kind of graphical thing which I want to be visible only to side moving the unit and not all sides.
With side=$side_number, the filter is checking to see if the unit that just moved is on the side whose turn it is. Of course it always will be. With $x1, $y1 it was also checking to see if the unit was where it is, which is also silly. (The [filter] decides whether or not to perform the action, not which side can see it if it does end up happening, so your objection doesn't make sense.)
enclave wrote:for some magical reason [filter_condition] makes my units stop before attacking
I'm pretty sure you can get around this by putting [allow_undo][/allow_undo] in the event. Try that. If your event is just graphical, it shouldn't hurt anything, and you'll probably want to do it eventually anyway.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Thank you for your reply beetlenaut, I just realized you most probably 100% right on the filter.. it just always felt like if I don't put x,y and side number then filter would work same as store unit.. filter everything on map.. while moveto event only gives me opportunity to filter precise coordinates to perform the filter.. if you specify them.. i'm still confused.. so I can't filter anything else except the moving unit on moveto event? why would it need filter at all then? I just woke up, sorry if I sound stupid..
beetlenaut wrote:I'm pretty sure you can get around this by putting [allow_undo][/allow_undo] in the event. Try that. If your event is just graphical, it shouldn't hurt anything, and you'll probably want to do it eventually anyway.
Unfortunately like I mentioned in my original long post, I can't apply allow_undo.. it contains not only graphics.. but some coordinates as well.. so if I make undo, there are multiple bad things happening.. 1) graphics remains where it is (version 1.12 doesnt let you do [on_undo] to the best of my knowledge), so enemy unit is still highlighted in red, my unit still highlighted in green.. 2) then if i perform the action related to graphics.. there is a lua error, which is more or less obvious.. coz i can't attack that unit from 5 hexes away or so..

I do it a bit complicated way.. When unit moves and he is matching the filter, i use [select_unit] to fire unsynchronized select event which uses graphics, this way enemy doesn't see the graphics.. but when i right click (menu) on enemy unit, the attack is happening with wesnoth.synchronize_choice using data from select event.. wihout lua [item] works quite slow to put highlighted image on map.. because with [item] i could specify to show image to my team only (but again, I don't want my ally to see it either.. so unsynchronized event works best for me).. having this complicated code it's hard to make [allow_undo] not hurt anything.. Thanks for idea anyway..
User avatar
beetlenaut
Developer
Posts: 2813
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: enclave's WML Macros questions Thread

Post by beetlenaut »

enclave wrote:so I can't filter anything else except the moving unit on moveto event? why would it need filter at all then?
Right: The unit that just moved is sent to the event, and that's what you are filtering. You can use the filter to make sure the moved unit is on side 1, or is a leader, or is now on hex 3,10 for example. If you need to work with another unit during the event, you can use [if] plus [have_unit]. In fact, when you have first_time_only=no, you can do everything with [if] statements. Sometimes that's easier.
enclave wrote:I make undo, there are multiple bad things happening
Fair enough. I missed that in the earlier post.
enclave wrote:What am I doing wrong? how to write it shorter?
This code could be shortened using macros I guess. However, you seem to be a little unclear about filters, so there might be a shorter way to do what you want in the first place. But, since I still can't tell exactly what that is, it's hard to come up with useful suggestions.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Thanks very much beetlenaut, I will keep in mind the [if][have_unit], it might be useful at some point, didn't realize that opportunity at all.. but will it work longer than [filter]? Anything could be done with [store_unit] as well, but I don't think it would be a quick and efficient way at all.. or am I wrong?
This code could be shortened using macros I guess. However, you seem to be a little unclear about filters, so there might be a shorter way to do what you want in the first place. But, since I still can't tell exactly what that is, it's hard to come up with useful suggestions.
I guess if you haven't come up with some alternative straight away then there is no perfect alternative.. It's all I needed to know, - do I do it completely stupid and long way, or it's not too bad.. so I assume it's not too bad.. (my final code looks like this:
Spoiler:
)
By shorter I didn't mean more neat and tidy, I rather meant more efficient.. so macros won't help me..
Thanks very much for all the answers.. it was really helpful!
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Hi,

I know there is a code like this to select a unit:

Code: Select all

	[select_unit]
		x,y=$x1,$y1
		fire_event=yes
	[/select_unit]
but is there anything to deselect it? Thanks very much..
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

A question...
Does anyone know a better solution to determine whether the variable is number or a string.. using WML
Here is how I done it:
I have a text input:

Code: Select all

[text_input]
	label="Enter number here (letters will result in error):"
	variable=input_text_result
[/text_input]
And then I have a code check:

Code: Select all

[if]
   [variable]
         name=input_text_result
         greater_than=0
   [/variable]
   [and]
      [variable]
          name=input_text_result
          less_than=100000
      [/variable]
   [/and]
   [then]
            ## my code if user entered the number  >0 and <100000
   [/then]
   [else]
           ## error message if user entered a letter or sentance or number less than 1 or greater than 99999
   [/else]
[/if]
The problem with my code is that I can not use 0 in the input field.. if i use greater_than_equal_to=0 instead of greater_than=0 then it will stop recognizing letters etc.. user would be able to enter anything he likes, sentance.. letters... and there will be no error message and then there will be a bug in the future WML resulting in who knows what problems and errors.. that would most probably corrupt the game.
Anyone knows code that would allow me to use any numbers in the input field? but would call error message if there is anything other than number? (WML, not lua)

Thanks!

PS. i think i found the way.. that's how I fixed it:

Code: Select all

[if]
   [variable]
        name=input_text_result
        greater_than=0
   [/variable]
   [and]
      [variable]
        name=input_text_result
        less_than=100000
      [/variable]
   [/and]
   [or]
      [variable]
         name=input_text_result
         equals=0  ## funny that numerical_equals didnt work unlike I assumed..
      [/variable]
   [/or]
   [then]
            ## my code if user entered the number of >-1 and <100000
   [/then]
   [else]
           ## error message if user entered a letter or sentance or number less than 0 or greater than 99999
   [/else]
[/if]
but maybe anyone knows more simple way? I couldnt find it in wiki..
User avatar
beetlenaut
Developer
Posts: 2813
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: enclave's WML Macros questions Thread

Post by beetlenaut »

You'll just have to do some extra checking. If it numerically_equals = 0, but doesn't also equals = "0", then you know they entered some non-numbers. Otherwise, they entered something valid.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Pentarctagon
Project Manager
Posts: 5496
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: enclave's WML Macros questions Thread

Post by Pentarctagon »

Lua also has the ability to check with the type() function.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
gfgtdf
Developer
Posts: 1431
Joined: February 10th, 2013, 2:25 pm

Re: enclave's WML Macros questions Thread

Post by gfgtdf »

Pentarctagon wrote:Lua also has the ability to check with the type() function.
but note that wml attributes aren't always passed as numbrs to lua code even if they are valid numbers (this mainly applies to floats). So it's probably better to use tonumber(value) ~= nil to check whether am attribute is a valid number.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Post Reply