Lua error on porting existing wml from 1.12 to 1.14.4

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

Moderators: Forum Moderators, Developers

Post Reply
Spannerbag
Posts: 14
Joined: December 18th, 2016, 6:14 pm

Lua error on porting existing wml from 1.12 to 1.14.4

Post by Spannerbag » August 6th, 2018, 11:00 pm

Hi all,

I started writing a campai(g)n longer ago than I care to think on v1.12.
With 24 scenarios completed and playable I decided that I'd upgrade to 1.14.4 as I needed to check everything worked on the latest release.
My PC runs Windows 7 Home Premium Service Pack 1 and has Intel i3 so it's not great but meets the minimum spec and seems to run Wesnoth 1.14.4 OK.

Anyway I ugraded ... hmmm...

Fixed the slashes (I'd used Windows not forward slashes) then was wondering why on earth scenario 2 wouldn't load my leader.
Turns out I needed to specify leader type in [side].
I've now hit another issue and this time it's Lua.

I have a sighted event that assigns leaders, gold and income to 2 sides when a player's unit sights any of them.
Until then both [side]s have

Code: Select all

    income= -2		# Zero income until sighted
    gold= 0
I've tried the wml with and without a space after the "=" (couldn't think of anything else to try!) but no luck.

This all worked fine in 1.12?
Here's the WML that I think the Lua error originates from:

Code: Select all

    [modify_side]
      side=2
      {GOLD 35, 40, 45}
      {INCOME 10, 13, 16}
    [/modify_side]
    [modify_side]
      side=3
      {GOLD 45, 50, 55}
      {INCOME 4 7 10}
    [/modify_side]
The Lua error text is:

<Lua error> lua/wml/modify_side.lua:42: attempt to perform arithmetic on a string value (field 'income')
stack traceback:
lua/wml/modify_side:42: 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>


Any idea what caused this and how best to fix?

I'm a bit concerned because the later scenarios do an awful lot of chopping and changing of leaders and armies - that is, I haven't got to anything complex yet and I'm finding multiple issues. Could it be my PC? Do I need to add something? (Please don't all shout "linux!" at once :) )

Anyway, any ideas/suggestions etc. gratefully received.

Might not be able to respond for about 48 hours but will reply when I can.

Thanks in advance for any advice.

Cheers!

User avatar
Pentarctagon
Forum Administrator
Posts: 3542
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Lua error on porting existing wml from 1.12 to 1.14.4

Post by Pentarctagon » August 6th, 2018, 11:48 pm

Does the error remain if you remove one or the other [modify_side]s? It could be that it doesn't like the commas in the first use of the INCOME macro.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

User avatar
Elvish_Hunter
Developer
Posts: 1375
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Lua error on porting existing wml from 1.12 to 1.14.4

Post by Elvish_Hunter » August 7th, 2018, 9:40 am

You aren't supposed to use commas to separate macro arguments. Use just spaces instead.
However, I think that we could make the error message clearer: for example, the file /data/lua/wml/modify_side.lua might be modified by adding a line like

Code: Select all

local income = tonumber(cfg.income) or helper.wml_error("[modify_side]: expected number in income= key, got string instead")
Current maintainer of these add-ons:
1.14: The Sojournings of Grog, A Rough Life, The White Troll (co-author), Wesnoth Lua Pack
1.12: Children of Dragons
Active again until mid-October

enclave
Posts: 836
Joined: December 15th, 2007, 8:52 am

Re: Lua error on porting existing wml from 1.12 to 1.14.4

Post by enclave » August 7th, 2018, 10:19 am

or just dont use macros inside modify side... why would u need them... {GOLD..}

Spannerbag
Posts: 14
Joined: December 18th, 2016, 6:14 pm

Re: Lua error on porting existing wml from 1.12 to 1.14.4

Post by Spannerbag » August 7th, 2018, 8:59 pm

Pentarctagon wrote:
August 6th, 2018, 11:48 pm
Does the error remain if you remove one or the other [modify_side]s? It could be that it doesn't like the commas in the first use of the INCOME macro.
Yup, that fixed it... D'Oh! :doh:

I really should take a break now and then.
It was getting late, I was tired and had looked repeatedly at those lines and didn't see anything wrong. I'd gone "comma-blind"...

Anyhows, thanks to all who pointed out the spurious commas, muchly appreciated thanks.

Only about 21 scenarios to check (with multiple pathways).
Then another ~6 to write. Then I'll be done. Wonder if I'll live long enough? :roll:

Thanks again to all of you who took the trouble to reply.

Hopefully you'll get to play the damn thing eventually!

Post Reply