Another basic lua query

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

User avatar
Spannerbag
Posts: 780
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Another basic lua query

Post by Spannerbag »

Ravana wrote: Yesterday, 2:32 pm ...__cfg of unit has specific meaning (similar to [store_unit])....
Good to know unit context of __cfg, thanks. :)

Ravana wrote: Yesterday, 2:32 pm ... __ attributes and functions are not implemented in Lua but anyways you need to check documentation.
When the ***** documentation is helpful... :augh:

Thanks for the clarification!

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.18, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 780
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Another basic lua query: syntax query #2

Post by Spannerbag »

gnombat wrote: Yesterday, 2:54 pm Try this:

Code: Select all

local my_filter = {
  side = wesnoth.current.side,
  { "filter_adjacent", { id = target.id } }
}
my_filter = wml.merge(filter_follower, my_filter, 'append')
wesnoth.interface.add_chat_message(wml.tostring(my_filter))
8)

Faffed around for awhile trying to understand why variables were correctly interpreted sometimes but not always.
Don't fully know why but am 99% certain it's my lack of familiarity with lua :doh:
Anyway got the following to run without errors - :D - and it returned expected/hoped for/correct values.
It even seemed to produce the desired behaviour! :shock:

Code: Select all

  local filter_follower = wml.get_child(cfg, "filter_follower")

-- Debug
  local my_filter = wml.merge(filter_follower, { side = wesnoth.current.side, wml.tag.filter_adjacent { id = target.id } } )
  wesnoth.interface.add_chat_message(wml.tostring(my_filter))

  local adj_followers = wesnoth.units.find_on_map ( wml.merge(filter_follower, { side = wesnoth.current.side, wml.tag.filter_adjacent { id = target.id } } ) )
 
Seems to produce identical outputs with or without append however it was good to demonstrate that syntax as I'd struggles with that, too. :augh:

With append:
wtest.jpg
wtest.jpg (123.46 KiB) Viewed 39 times
Without
wtestnoappend.jpg
wtestnoappend.jpg (107.28 KiB) Viewed 39 times
Whilst it probably wasn't worth all this effort just to remove a few and clauses, I've learned a bit more about lua! :thumbsup:

Thanks to everyone who took the trouble to reply, your time and trouble are greatly appreciated.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.18, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
Post Reply