Wesnoth Lua Pack: Development Thread

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

Moderator: Forum Moderators

Post Reply
User avatar
Celtic_Minstrel
Developer
Posts: 1957
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Wesnoth Lua Pack: Development Thread

Post by Celtic_Minstrel »

Glancing over the WLP on GitHub, I notice that some of the things it implements are now in mainline, while others perhaps could be migrated to mainline… there are certainly things that probably don't need to be migrated to mainline as well, though.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Elvish_Hunter
Forum Moderator
Posts: 1532
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter »

When you wrote on IRC about that, I answered you through Discord; however, because in that moment your client wasn't in the channel, you never saw my answer :(
This is the conversation as it was supposed to happen:

Code: Select all

02:12:29 <celticminstrel> Elvish_Hunter: Looking at WLP, I notice that most of the Lua utils seem to be redundant now?
02:13:08 <celticminstrel> Also redundant are [alert] and [confirm].
02:13:30 <celticminstrel> [choice_box] might be, I can't quite remember.
02:13:38 <celticminstrel> (Assuming it does what it sounds like.)
02:14:09 <celticminstrel> (Tags being redundant means they can be roughly a one-liner.)
02:19:41 <celticminstrel> I think most of the math/variable tags would do better merged to mainline…
02:20:04 <celticminstrel> (As part of [set_variable] or maybe [set_variables], though I think none fit the latter.)
02:25:10 <celticminstrel> I think it's totally worth it to add gui.prompt() as a standard dialog in Wesnoth. Maybe I could steal the definition from WLP?
09:31:30 <+wesdiscordbot> <Elvish_Hunter> celticminstrel: about [choice_box], you can read its documentation here: https://github.com/Elvish-Hunter/Wesnoth_Lua_Pack/blob/master/docs/InterfaceActionsWML.md
09:33:03 <+wesdiscordbot> <Elvish_Hunter> The math tags and [prompt] can be added to mainline, if you want.
09:42:10 <+wesdiscordbot> <Elvish_Hunter> Once you decide what code or tags should be moved to mainline, please notify me in some way, so I can remove the obsolete stuff from the WLP.
09:45:25 <+wesdiscordbot> <Elvish_Hunter> BTW, can you put in https://wiki.wesnoth.org/LuaAPI a list of all the functions that have been renamed or moved into a module and the corresponding new name?
09:46:41 <+wesdiscordbot> <Elvish_Hunter> It'd make updating UMC Lua code easier, even if someone doesn't read the changelog.
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)
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Wesnoth Lua Pack: Development Thread

Post by vghetto »

Hi,

The [get_recruit_list] tag throws an error when [filter] is used.

Code: Select all

[get_recruit_list]
        [filter_side]
                side=1
        [/filter_side]
        [filter]
                side=1
        [/filter]
        variable=recruit_list
[/get_recruit_list]

Code: Select all

20210427 22:55:02 error scripting/lua: ~add-ons/Wild_Frontiers/lua/utils.lua:294: attempt to index a vconfig value (local 'filter')
stack traceback:
        ~add-ons/Wild_Frontiers/lua/utils.lua:294: in local 'cmd'
        lua/wml-utils.lua:145: in field 'handle_event_commands'
        lua/wml-flow.lua:6: in function <lua/wml-flow.lua:5>
The error corresponds to the line 634 in wml-tags.lua

Code: Select all

                        filter.side = side.side -- to avoid collecting extra_recruit from enemies
User avatar
Celtic_Minstrel
Developer
Posts: 1957
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Wesnoth Lua Pack: Development Thread

Post by Celtic_Minstrel »

I think the following replacement for that line should fix the issue:

Code: Select all

filter = wml.literal(filter)
filter.side = side.side
filter = wml.tovconfig(filter)
If that doesn't work, try wesnoth.tovconfig and either helper.literal or H.literal.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Elvish_Hunter
Forum Moderator
Posts: 1532
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter »

Thank you for reporting this issue. I'll try to fix it as soon as I can.
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)
User avatar
Elvish_Hunter
Forum Moderator
Posts: 1532
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter »

Somewhat later than I originally planned, I just uploaded version 1.9.0 of the Wesnoth Lua Pack both on the 1.16 add-ons server and on the GitHub repository.
This version mainly features updates to be compliant with the refactored Lua API (which means that no deprecation warnings should be issued, unless I missed something); there are also a few deprecated tags (whose purpose can now be fulfilled by the [set_variable] tag and which I'm probably going to remove in version 1.10.0), a few bug fixes and a small test scenario which can be accessed by running Wesnoth in debug mode.
As usual, please report any issue that you find (either in this thread or on GitHub) and don't forget to propose anything that you'd like to see added to this pack!
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)
User avatar
Spannerbag
Posts: 216
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Candidate WML tag [gold_min]

Post by Spannerbag »

Hello,
It's been suggested the following bit of lua may be suitable for inclusion in the lua pack.
Also had feedback that my current method of implementation is not optimal.

Code exists for versions 1.4 and 1.6.
Code and usage notes for 1.6 version are given below (and also in first link above):

Code: Select all

-- Wesnoth 1.15+

function wesnoth.wml_actions.gold_min(cfg)
  local gm_amount = tonumber(cfg.amount) or wml.error "[gold_min] missing required amount= attribute."
  local gm_min = tonumber(cfg.min) or gm_amount
  local sides = wesnoth.sides.find(cfg)
  for index, team in ipairs(sides) do
    team.gold = team.gold + gm_amount
    if team.gold < gm_min then team.gold = gm_min end
  end
end

Code: Select all

# Custom tag [gold_min] used to (slightly) reduce WML bloat
#
# Keys
#	side:	Side(s) to modify gold for.  Can be a single side or a comma separated list.
#		Note: [filter_side] does not seem to work (all sides are included).
#
# 	amount:	Gold to be given to side(s) above.  Required.
#
#	min:	Minimum gold that side(s) must have.  Optional, if omitted min defaults to amount.
#
#
# Function
#
#	max( side gold+min, min ) for each side
#
#
# Example 1
# 
# [gold_min]
#   side=1,2,3
#   amount=35
# [/gold_min]
#
# Side gold before/after execution of WML above:
# side 1=100/135, side 2=-23/35, side 3=0/35.
# Note: min omitted so defaults to amount (=35).
#
#
# Example 2
#
# [gold_min]
#   side=1,2,4
#   amount=35
#   min=20
# [/gold_min]
#
# Side gold before/after execution of WML above:
# side 1=100/135, side 2=-23/20, side 3=0/35.
#
#
# Credits
#
# Many thanks to all those on the forum who did all the hard work for me:
# Luther, vghetto, Elvish_Hunter and Pentarctagon
# If you are interested, my various consufions and failures can be viewed on the forum:
# https://forums.wesnoth.org/viewtopic.php?f=58&t=54347
# https://forums.wesnoth.org/viewtopic.php?f=58&t=54540
# https://forums.wesnoth.org/viewtopic.php?f=12&t=54045

  [lua]
    code="wesnoth.require '~add-ons/LSB/lua/gold_min.lua'"
  [/lua]
Cheers!
--Spannerbag
UMC Campaign: After EI
I suspect the universe is simpler than we think and stranger than we can know.
User avatar
Elvish_Hunter
Forum Moderator
Posts: 1532
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Wesnoth Lua Pack: Development Thread

Post by Elvish_Hunter »

Spannerbag wrote: February 21st, 2022, 1:14 pm It's been suggested the following bit of lua may be suitable for inclusion in the lua pack.
Merged into the WLP thread.
For the 1.16 WLP, this looks like a serious candidate, so I'll most likely add it.
For 1.17, probably a better idea would be to improve the existing [gold] tag with the addition of a new key: there are several situations when being able to guarantee that a side ends up with at least a certain amount of gold is useful.
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)
User avatar
Spannerbag
Posts: 216
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Wesnoth Lua Pack: Development Thread

Post by Spannerbag »

Elvish_Hunter wrote: February 22nd, 2022, 8:01 pm
Spannerbag wrote: February 21st, 2022, 1:14 pm It's been suggested the following bit of lua may be suitable for inclusion in the lua pack.
Merged into the WLP thread.
For the 1.16 WLP, this looks like a serious candidate, so I'll most likely add it.
For 1.17, probably a better idea would be to improve the existing [gold] tag with the addition of a new key: there are several situations when being able to guarantee that a side ends up with at least a certain amount of gold is useful.
FWIW that would be my preferred solution as well :)

Cheers!
--Spannerbag
UMC Campaign: After EI
I suspect the universe is simpler than we think and stranger than we can know.
User avatar
egallager
Posts: 358
Joined: November 19th, 2020, 7:27 pm
Location: Concord, New Hampshire
Contact:

Re: Wesnoth Lua Pack: Development Thread

Post by egallager »

So, The Earth's Gut uses the WLP, and I've recently been messing with some of the lua in it and uncommented a bunch of calls to dbms(), and now I'm kind of confused by what exactly it's telling me... could someone help me understand it? I opened an issue about it, btw: https://github.com/Elvish-Hunter/Wesnoth_Lua_Pack/issues/6
Wesnoth-related GitHub repos:
General mods collection, SotBEEE, AToTBWaTD, The Earth's Gut, A Little Adventure, FtF
Social media: Mastodon: @egallager@home.social, Steam: egallager
Post Reply