ForestDragon's WML questions

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Ravana
Moderator
Posts: 1786
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: ForestDragon's WML questions

Post by Ravana » June 26th, 2018, 11:49 am

Yes, that is part of cfg.

wml.get_child(cfg, "filter")

User avatar
ForestDragon
Forum Regular
Posts: 1471
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » June 26th, 2018, 12:03 pm

Ravana wrote:
June 26th, 2018, 11:49 am
Yes, that is part of cfg.

wml.get_child(cfg, "filter")
Thanks. Where should the code be put, though? Also, should the message be like wesnoth.message("unstore_unit:",cfg.variable,cfg.filter), or something else?
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned) and The Golden Age (1.12/1.13, temporarily abandoned again),XP Bank (now on 1.14),Alliances Mod(1.12, unplayable)
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1786
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: ForestDragon's WML questions

Post by Ravana » June 26th, 2018, 12:15 pm

wesnoth.message takes 1 or 2 arguments, you can not give it 3.

Filter is not attribute, so cfg.filter doesnt give anything. You need to get filter child instead. You might need https://wiki.wesnoth.org/LuaWML/Misc#wesnoth.debug if you want to show filter table as string.

User avatar
ForestDragon
Forum Regular
Posts: 1471
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » June 26th, 2018, 12:26 pm

Ravana wrote:
June 26th, 2018, 12:15 pm
wesnoth.message takes 1 or 2 arguments, you can not give it 3.

Filter is not attribute, so cfg.filter doesnt give anything. You need to get filter child instead. You might need https://wiki.wesnoth.org/LuaWML/Misc#wesnoth.debug if you want to show filter table as string.
where should I insert wesnoth.debug() into the following code?

Code: Select all

    [event]
        name=preload
	[lua]
code=<<
local old = wesnoth.wml_actions.store_unit
function wesnoth.wml_actions.store_unit(cfg)
wesnoth.message("store_unit:",cfg.variable)
old(cfg)
end
local old = wesnoth.wml_actions.unstore_unit
function wesnoth.wml_actions.unstore_unit(cfg)
    wesnoth.message("unstore_unit:",cfg.variable)
    old(cfg)
end
>>
        [/lua]
    [/event]
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned) and The Golden Age (1.12/1.13, temporarily abandoned again),XP Bank (now on 1.14),Alliances Mod(1.12, unplayable)
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1786
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: ForestDragon's WML questions

Post by Ravana » June 26th, 2018, 12:28 pm

That code does not need it. It is used to format table as string, and cfg.variable already is string.

You might want wesnoth.message("unstore_unit:",wesnoth.debug(wml.get_child(cfg,"filter")))

User avatar
ForestDragon
Forum Regular
Posts: 1471
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » June 26th, 2018, 12:32 pm

Ravana wrote:
June 26th, 2018, 12:28 pm
That code does not need it. It is used to format table as string, and cfg.variable already is string.
ok, but could you please post an a working example of an application of the wesnoth.debug() code, as reference?
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned) and The Golden Age (1.12/1.13, temporarily abandoned again),XP Bank (now on 1.14),Alliances Mod(1.12, unplayable)
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1786
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: ForestDragon's WML questions

Post by Ravana » June 26th, 2018, 12:43 pm

Never used it, I implemented my own function to inspect tables https://github.com/ProditorMagnus/Oroci ... ctions.lua

User avatar
ForestDragon
Forum Regular
Posts: 1471
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » June 26th, 2018, 12:52 pm

Is it possible to instead do something like "wesnoth.message("store_unit:",cfg.variable.id)"?
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned) and The Golden Age (1.12/1.13, temporarily abandoned again),XP Bank (now on 1.14),Alliances Mod(1.12, unplayable)
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1786
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: ForestDragon's WML questions

Post by Ravana » June 26th, 2018, 12:54 pm

No, you need to use get_child to get anything from subtag.

wml.get_child(cfg,"filter").id

User avatar
ForestDragon
Forum Regular
Posts: 1471
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » June 26th, 2018, 12:57 pm

Ravana wrote:
June 26th, 2018, 12:54 pm
No, you need to use get_child to get anything from subtag.

wml.get_child(cfg,"filter").id
ok, but how do I write the result of the gotten wml child? (instead of cfg.x.y)
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned) and The Golden Age (1.12/1.13, temporarily abandoned again),XP Bank (now on 1.14),Alliances Mod(1.12, unplayable)
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1786
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: ForestDragon's WML questions

Post by Ravana » June 26th, 2018, 12:58 pm

What you mean as result?

User avatar
ForestDragon
Forum Regular
Posts: 1471
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » June 26th, 2018, 1:00 pm

Ravana wrote:
June 26th, 2018, 12:58 pm
What you mean as result?
the child content, like ".id", for example.
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned) and The Golden Age (1.12/1.13, temporarily abandoned again),XP Bank (now on 1.14),Alliances Mod(1.12, unplayable)
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1786
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: ForestDragon's WML questions

Post by Ravana » June 26th, 2018, 1:00 pm

wesnoth.message(wml.get_child(cfg,"filter").id)

User avatar
ForestDragon
Forum Regular
Posts: 1471
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » June 26th, 2018, 1:08 pm

ok, thanks.
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned) and The Golden Age (1.12/1.13, temporarily abandoned again),XP Bank (now on 1.14),Alliances Mod(1.12, unplayable)
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
ForestDragon
Forum Regular
Posts: 1471
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » June 26th, 2018, 1:15 pm

another question on the topic: is it possible extract one of a list of values from a table like "filter" with the previous code? (with a list of possible values, like .id and.type, with one of the two being chosen if either was in the filter)
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned) and The Golden Age (1.12/1.13, temporarily abandoned again),XP Bank (now on 1.14),Alliances Mod(1.12, unplayable)
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

Post Reply