tekelili advanced WML questions

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
User avatar
artisticdude
Moderator Emeritus
Posts: 2424
Joined: December 15th, 2009, 12:37 pm
Location: Somewhere in the middle of everything

Re: tekelili WML noob questions

Post by artisticdude »

SlowThinker wrote:items within the menu are ordered by id=
Adding to that, they are specifically ordered by id numerically, then alphabetically. So, for example, if you want a menu item with the id=inventory to be above the menu item with id=help, you could change the id's to id=1inventory and id=2help. That will ensure that the game always places the inventory command above the help command. And of course, you don't even necessarily need to have the command's id match its right-click menu description, though I still recommend you try and keep them synchronized as closely as possible to avoid any unnecessary confusion. :)
"I'm never wrong. One time I thought I was wrong, but I was mistaken."
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: tekelili WML noob questions

Post by tekelili »

How divide a variable and get a foating point result?
To be more precise, my current problem is this: I want divide a variable and round result to up integer if decimal part > 0.5 or round to low integer if decimal part <= 0.5
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: tekelili WML noob questions

Post by Anonymissimus »

1.8: I'd try making the engine guess that you want floats; e.g don't use
[set_variable]divide=2
use
[set_variable]divide=2.0

In 1.9 you probably don't have that problem at all and I would personally use lua for it. Or formula language. Probably. Unless the whole thing I calculate there is simple enough.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: tekelili WML noob questions

Post by tekelili »

It is neccessary clear variables in a multiplayer scenario of just 1 map?
Until now, I have tried be clean while coding and clear all variables in the very moment they are not longer needed. But am working in a scenario that calls lot of subrutines that are iterated over long arrays, and I am interested in reduce as many steps as possible to improve speed. As I have no idea if dont clean variables will affact user once he ends scenario, hence my question.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: tekelili WML noob questions

Post by Anonymissimus »

tekelili wrote:It is neccessary clear variables in a multiplayer scenario of just 1 map?
Until now, I have tried be clean while coding and clear all variables in the very moment they are not longer needed. But am working in a scenario that calls lot of subrutines that are iterated over long arrays, and I am interested in reduce as many steps as possible to improve speed. As I have no idea if dont clean variables will affact user once he ends scenario, hence my question.
WML interpretation is very slow, so that it does not matter much how performance-efficient wml code is. What causes lag is "wml bloat", the quantity of the whole wml of a scenario getting written to disk in autosaves, usually caused by overusage of macros to insert code into each other instead of custom events or lua. Personally I've noticed that complex SLFs can slow down at times (because the engine's SLF implementation isn't very efficient).
As for variables in a single scenario, in case they are scalar ones there's no need to care I think. Other than readability of the :inspect dialog. Of course since variables can contain arbitrarily complex wml they can also be subject of the above.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: tekelili WML noob questions

Post by SlowThinker »

Anonymissimus wrote:What causes lag is "wml bloat", the quantity of the whole wml of a scenario getting written to disk in autosaves, usually caused by overusage of macros to insert code into each other instead of custom events or lua.
I have a question that is slightly related to the wml bloat: if the addon contains its base WML code and contains many scenarios, the base WML is repeated in each scenario, and so the WML code becomes very bloated. I suppose I can avoid this if I put all the base WML code (i.e. the code that is common for all scenarios) into an era? Am I right? (I guess that measure won't decrease the size of saves thought)

But now what to do if I need to use another external era(s) with my add-on? Can I include the file with the external_era into the code of my_addon_era?
Anonymissimus wrote:Personally I've noticed that complex SLFs can slow down at times (because the engine's SLF implementation isn't very efficient).
What is SLF?
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
User avatar
Crendgrim
Moderator Emeritus
Posts: 1328
Joined: October 15th, 2010, 10:39 am
Location: Germany

Re: tekelili WML noob questions

Post by Crendgrim »

SLF = StandardLocationFilter.
UMC Story Images — Story images for your campaign!
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: tekelili WML noob questions

Post by Anonymissimus »

SlowThinker wrote:if the addon contains its base WML code and contains many scenarios, the base WML is repeated in each scenario, and so the WML code becomes very bloated. I suppose I can avoid this if I put all the base WML code (i.e. the code that is common for all scenarios) into an era? Am I right? (I guess that measure won't decrease the size of saves thought)
I suppose that wouldn't help. Pretty unsure though.
The [event]s an era contains are added to the scenario events and saved with it. I suppose that happens when the scenario is preprocessed, which happens only on the host, and then the whole scenario gets sent to the remote clients. What gets sent should be quite similar to a savegame. The events from a require_era=no era are sent to the remote clients (which don't have the era) as well so it must be about this way.
SlowThinker wrote:But now what to do if I need to use another external era(s) with my add-on? Can I include the file with the external_era into the code of my_addon_era?
Only 1 era can be used in a MP game at the same time unfortunately. So what people do is that they create an additional era within their addon for each foreign era they want to support which adds support for the combination of the own and the foreign era. At least that's how Diplomacy Era, myself (PYAE) and Debug Era do it.
Including the foreign era's code may be possible (depends on the structure of the foreign code).
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: tekelili WML noob questions

Post by SlowThinker »

Anonymissimus wrote:1 era can be used in a MP game at the same time unfortunately. So what people do is that they create an additional era within their addon for each foreign era they want to support which adds support for the combination of the own and the foreign era. At least that's how Diplomacy Era, myself (PYAE) and Debug Era do it.
You mean they copy the code from Diplomacy era and customize it?
Anonymissimus wrote:Including the foreign era's code may be possible (depends on the structure of the foreign code).
Yes, a foreign code fragmented into many files is better.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: tekelili WML noob questions

Post by Anonymissimus »

SlowThinker wrote:
SlowThinker wrote:You mean they copy the code from Diplomacy era and customize it?
No. Unless it's impossible to reference it somehow.
So what I do is for instance

Code: Select all

[era]
...
	require_era=no
	{ERA_DEFAULT}
	{ERA_PYA}
[/era]
So I reuse the definition of ERA_DEFAULT in mainline (data/multiplayer/eras.cfg), and ERA_PYA is a custom macro containing [event]s.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
SlowThinker
Posts: 876
Joined: November 28th, 2008, 6:18 pm

Re: tekelili WML noob questions

Post by SlowThinker »

The advantage/disavantage of the reference is your add-on follows the changes done in new versions of the foreign era.
SlowThinker wrote:Yes, a foreign code fragmented into many files is better.
BTW I would like if WML allowed labels in the tags, like [add=my_label]. It could allow
  • to include an individual tag from the referenced file
  • to obtain an easier access deep into a variable: Now if you want to edit a code that is supposed to be applied by insert_tag then you must apply set_variable to filter[4].not[0].add[10].radius
for example. With the label you would apply it to my_label.radius (or to add=my_label.radius, i don't know which way is better).
I work on Conquest Minus • I use DFoolWide, Retro Terrain Package and the add-on 'High Contrast Water'
I moved to Nosebane's corner (Doc Paterson's signature); I am spending my time there, so PM me if I don't answer your post in forums
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: tekelili WML noob questions

Post by tekelili »

I want calculate this function: y=(5/6)^((x-1)/(x^(5/12)))

I guess I should use lua for that... if that is true, as I have no clue about it I wonder if anyone could give me the very code I should copy paste to calculate $y using $x
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: tekelili WML noob questions

Post by mattsc »

You can use Lua for this, of course, but unless I misunderstand what you want, you do not need to. You just put your equation inside $( ). For example, here's a moveto event that takes the unit's x coordinate and calculates the respective y from your function:

Code: Select all

    [event]
        name=moveto
        first_time_only=no

        [set_variable]
            name=y
            value=$( (5./6.)^(($unit.x-1)/($unit.x^(5./12.))) )
        [/set_variable]

        {MESSAGE $unit.id "" "" "y= $y"}
    [/event]
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: tekelili WML noob questions

Post by Sapient »

don't forget to put your $(...) inside a "..." :)
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: tekelili WML noob questions

Post by tekelili »

ty a lot guys for help, and sorry for silly question. I sometimes become ofuscated by the easiest problems :oops:
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Post Reply