Utter lua consufion
Moderator: Forum Moderators
- Spannerbag
- Posts: 505
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Utter lua consufion
Hi,
it's can't-code-lua-guy again...
My orignal lua query was sorted in double quick time, thanks again to all who took the trouble to help. I made the fatal error fo fiddling with it and I can't work out how I broke it
This is the original version which works, followed by the WML that calls it:
I was planning to publish this on the add-ons server as a maybe helpful widget but stupidly thought I'd "improve" it first.
What I wanted to do was lose the
Lua:
Proposed WML:
Logic:
Add
For each side if side.gold <
If
Seems simple, right?
When I run the new version I get
I've tried
Adding/omitting
Also purged cache and/or F5. Reboot made no difference either.
Both files have the same name so there's no change needed to
Clearly I'm doing something stupid but I can't see what?
Any help/suggestions greatly appreciated!
But I only changed a few lines...
Cheers!
--Spannerbag
it's can't-code-lua-guy again...
My orignal lua query was sorted in double quick time, thanks again to all who took the trouble to help. I made the fatal error fo fiddling with it and I can't work out how I broke it
This is the original version which works, followed by the WML that calls it:
Code: Select all
local helper = wesnoth.require "lua/helper"
function wesnoth.wml_actions.set_gold(cfg)
local set_amount = tonumber(cfg.amount) or helper.wml_error "[set_gold] missing required amount= attribute."
local sides = wesnoth.get_sides(cfg)
for index, team in ipairs(sides) do
team.gold = team.gold + set_amount
if cfg.set == true and team.gold < set_amount then team.gold = set_amount end
end
end
Code: Select all
[set_gold]
side=1
amount=100
set=yes
[/set_gold]
What I wanted to do was lose the
set
key but add an optional floor
key.Lua:
Code: Select all
local helper = wesnoth.require "lua/helper"
function wesnoth.wml_actions.set_gold(cfg)
local set_amount = tonumber(cfg.amount) or helper.wml_error "[set_gold] missing required amount= attribute."
local set_floor = tonumber(cfg.floor) or set_floor = tonumber(set_amount)
local sides = wesnoth.get_sides(cfg)
for index, team in ipairs(sides) do
team.gold = team.gold + set_amount
if team.gold < set_floor then team.gold = set_floor end
end
end
Code: Select all
[set_gold]
side=1
amount=100
floor=150
[/set_gold]
Add
amount
to gold for specified side(s).For each side if side.gold <
floor
then set side.gold = floor
.If
floor
omitted, set floor
=amount
Seems simple, right?
When I run the new version I get
<Invalid WML found> [set_gold] not supported
I've tried
set_floor = tonumber(set_amount)
and set_floor = set_amount
but no change.Adding/omitting
floor
makes no difference either.Also purged cache and/or F5. Reboot made no difference either.
Both files have the same name so there's no change needed to
_main.cfg
.Clearly I'm doing something stupid but I can't see what?
Any help/suggestions greatly appreciated!
But I only changed a few lines...
Cheers!
--Spannerbag
Re: Utter lua consufion
This line looks like a syntax error:
You can't do an assignment in the middle of an expression. Change it to this:
See if that works.
Lua errors should show up both in the scenario chat and in the terminal if you start Wesnoth from the command line.
Code: Select all
local set_floor = tonumber(cfg.floor) or set_floor = tonumber(set_amount)
Code: Select all
local set_floor = tonumber(cfg.floor) or tonumber(set_amount)
Lua errors should show up both in the scenario chat and in the terminal if you start Wesnoth from the command line.
Re: Utter lua consufion
Try the following:
Edit: oh, you already mentioned clearing the cache. I missed that. In that case I don't know, usually that error means the new tag was not loaded, and not that it crashed. I might be wrong.
Code: Select all
local set_floor = tonumber(cfg.floor) or set_amount
Try to clear wesnoth cache.When I run the new version I get <Invalid WML found> [set_gold] not supported
Edit: oh, you already mentioned clearing the cache. I missed that. In that case I don't know, usually that error means the new tag was not loaded, and not that it crashed. I might be wrong.
- Spannerbag
- Posts: 505
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: Utter lua consufion
Hi Luther,
You're right first time again
Many thanks for taking the time to respond, much appreciated!
Cheers!
--Spannerbag
You're right first time again
Seems to work fine under all code variantsLuther wrote: ↑June 30th, 2021, 5:07 pm This line looks like a syntax error:
You can't do an assignment in the middle of an expression. Change it to this:Code: Select all
local set_floor = tonumber(cfg.floor) or set_floor = tonumber(set_amount)
See if that works.Code: Select all
local set_floor = tonumber(cfg.floor) or tonumber(set_amount)
Lua errors should show up both in the scenario chat and in the terminal if you start Wesnoth from the command line.
Many thanks for taking the time to respond, much appreciated!
Cheers!
--Spannerbag