ForestDragon's 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
ForestDragon
Posts: 1766
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Hello everyone, another WML question: is it possible to edit the campaign laurel type mid-campaign? (Not having a difficulty choice at the start, but manually changing it to the golden type via an event). My intended application for this is an in-addon achivement system (the laurel type changing when copleting a specific achievement)
User avatar
ForestDragon
Posts: 1766
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Yet another WML question: is it possible, using tools like wmlint or the like, to view which events/tags are being triggered while in-game? (so that finding bugs is a bit less of a pain in the rear end)
User avatar
Ravana
Forum Moderator
Posts: 2934
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

You can override wesnoth.wml_actions.* to log when tag is entered.
User avatar
ForestDragon
Posts: 1766
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Ravana wrote: June 25th, 2018, 6:16 pm You can override wesnoth.wml_actions.* to log when tag is entered.
could you please be a bit more specific as to where this code should be put?
User avatar
Ravana
Forum Moderator
Posts: 2934
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

In [lua], usually under preload event. It is also possible to add it in core lua files.

Example of one tag

Code: Select all

local old = wesnoth.wml_actions.harm_unit
function wesnoth.wml_actions.harm_unit(cfg)
    wesnoth.message("harm_unit")
    old(cfg)
end
If you need that for many tags, would be useful do create array of tags you want to log and then iterate over them to modify them.

debug.traceback might be useful too. https://github.com/ProditorMagnus/Oroci ... it.lua#L27
User avatar
ForestDragon
Posts: 1766
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Ravana wrote: June 25th, 2018, 7:20 pm In [lua], usually under preload event. It is also possible to add it in core lua files.

Example of one tag

Code: Select all

local old = wesnoth.wml_actions.harm_unit
function wesnoth.wml_actions.harm_unit(cfg)
    wesnoth.message("harm_unit")
    old(cfg)
end
If you need that for many tags, would be useful do create array of tags you want to log and then iterate over them to modify them.

debug.traceback might be useful too. https://github.com/ProditorMagnus/Oroci ... it.lua#L27
Thanks, this is exactly what I needed. However, there seems to be a syntax error in the one-tag code you sent. Here's the slightly edited version of the code/error message:

Code: Select all

    [event]
        name=preload
	[lua]
local old = wesnoth.wml_actions.unstore_unit
function wesnoth.wml_actions.unstore_unit(cfg)#this is the line 23 mentioned in the error message
    wesnoth.message("unstore_unit")
    old(cfg)
end
        [/lua]
    [/event]
lua_error_message.png
User avatar
Ravana
Forum Moderator
Posts: 2934
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

With [lua] it works as

[lua]
code=<<
code
>>
[/lua]
User avatar
ForestDragon
Posts: 1766
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Ravana wrote: June 26th, 2018, 8:44 am With [lua] it works as

[lua]
code=<<
code
>>
[/lua]
works now, thanks. btw, is it possible to see which variable was unstored in the tag? (putting something like $wesnoth.wml_actions.unstore_unit.variable| in the log message)
User avatar
Ravana
Forum Moderator
Posts: 2934
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

Tags get their input as the first parameter - usually called cfg. So you would want to show cfg.variable. Lua string concatenation operator is ...
User avatar
ForestDragon
Posts: 1766
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Ravana wrote: June 26th, 2018, 8:57 am Tags get their input as the first parameter - usually called cfg. So you would want to show cfg.variable. Lua string concatenation operator is ...
Could please explain the last part (the Lua string concatenation operator) a bit more in detail?
User avatar
ForestDragon
Posts: 1766
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Ravana wrote: June 26th, 2018, 9:12 am Some old debugging code https://github.com/ProditorMagnus/Oroci ... #L122-L138
ok, thanks.
User avatar
ForestDragon
Posts: 1766
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

yet another small question regarding the debugging code: is it possible to store the location of the tag (file or line) as an output of the message?
User avatar
Ravana
Forum Moderator
Posts: 2934
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

Not really, all wml is dumped to one virtual file before it is evaluated.
User avatar
ForestDragon
Posts: 1766
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Ravana wrote: June 26th, 2018, 11:14 am Not really, all wml is dumped to one virtual file before it is evaluated.
oh,ok. is at least possible to store a tag's [filter] values?
Post Reply