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

Re: ForestDragon's WML questions

Post by Ravana »

Yes, that is part of cfg.

wml.get_child(cfg, "filter")
User avatar
ForestDragon
Posts: 1769
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

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?
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

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

Re: ForestDragon's WML questions

Post by ForestDragon »

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]
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

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

Re: ForestDragon's WML questions

Post by ForestDragon »

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?
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

Never used it, I implemented my own function to inspect tables https://github.com/ProditorMagnus/Oroci ... ctions.lua
User avatar
ForestDragon
Posts: 1769
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Is it possible to instead do something like "wesnoth.message("store_unit:",cfg.variable.id)"?
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

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

wml.get_child(cfg,"filter").id
User avatar
ForestDragon
Posts: 1769
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

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)
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

What you mean as result?
User avatar
ForestDragon
Posts: 1769
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

Ravana wrote: June 26th, 2018, 12:58 pm What you mean as result?
the child content, like ".id", for example.
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana »

wesnoth.message(wml.get_child(cfg,"filter").id)
User avatar
ForestDragon
Posts: 1769
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

ok, thanks.
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
User avatar
ForestDragon
Posts: 1769
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: ForestDragon's WML questions

Post by ForestDragon »

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)
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Post Reply