lua_function in Location Filter

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
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

lua_function in Location Filter

Post by gfgtdf »

in StandartUnitFilters i can use the lua_function attribute, is there a way to do the same in a LocationFilter?
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.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: lua_function in Location Filter

Post by Anonymissimus »

Try [filter_location][filter]lua_function=; I think it requires a unit to be at the location though. But other than that, you could put whatever conditions into that function.
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
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: lua_function in Location Filter

Post by gfgtdf »

but there is normaly no unit on that hex.
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.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: lua_function in Location Filter

Post by Anonymissimus »

Well, then: no.
And btw, good job with that boost bug workaround.
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
iceiceice
Posts: 1056
Joined: August 23rd, 2013, 2:10 am

Re: lua_function in Location Filter

Post by iceiceice »

Maybe you can e.g. temporarily place a fog clearer there and remove after?
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: lua_function in Location Filter

Post by gfgtdf »

@Anonymissimus
have you tested it? the last version should not create bugged gz files at all.

@iceiceice:
no that was supposed to be a filter for a right click menu items, so i dont knever know when it will happen.


maybe i can create somthing like a terrain overlay terrain wich defines wether there can can be klicked or not. Or i make pull request it shouldnt be too hard to add, or i do other things first and then think about it again, if i still think i need this.
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.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: lua_function in Location Filter

Post by Anonymissimus »

gfgtdf wrote:have you tested it? the last version should not create bugged gz files at all.
Not only are the crashes gone. Since MSVC debugger can use the wml cache now, relaunching into the test scenario takes roughly a whole minute less than before now. So, very useful at a very low cost code-wise. Excellent. (Kind of a typical wesnoth bug, some bug which is also a bug on Linux but just not as noticable and unfixed due to lack of windows devs.)
iceiceice wrote:Maybe you can e.g. temporarily place a fog clearer there and remove after?
How could one place a unit from within a location/unit/whatever filter ? lua_function= could do it yes but :doh: .
So, one would need two loops, one before and one after the filter call, to place a unit on all hexes and remove them afterwards. I don't suppose that's a good idea on anything but small maps.
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
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: lua_function in Location Filter

Post by Elvish_Hunter »

iceiceice wrote:Maybe you can e.g. temporarily place a fog clearer there and remove after?
iceiceice wrote:@iceiceice:
no that was supposed to be a filter for a right click menu items, so i dont knever know when it will happen.
Why don't you try describing us what kind of filter do you need? It may even turn out that you won't need lua_function at all. :)
Anonymissimus wrote:How could one place a unit from within a location/unit/whatever filter ? lua_function= could do it yes but :doh: .
In fact, lua_function= 's purpose is to take a unit and pass it as an argument to a function. Here there is an old example that I made:

Code: Select all

             function is_enemy( unit )
                if wesnoth.is_enemy( 1, unit.side ) then
                   return true
                end
             end

Code: Select all

            [if]
                [have_unit]
                    lua_function=is_enemy
                    [filter_vision]
                        visible=yes
                        viewing_side=1
                    [/filter_vision]
                [/have_unit]
Ideally, it should be a really short function, like lambdas in Python, and its only purpose should be to check if a unit meets certain criteria or not. Using a compare function to do other stuff but comparing seems like a recipe for disaster to me. :eng:
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Post Reply