Lua error on porting existing wml from 1.12 to 1.14.4

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

Moderator: Forum Moderators

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

Lua error on porting existing wml from 1.12 to 1.14.4

Post by Spannerbag »

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!
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, 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
Pentarctagon
Project Manager
Posts: 5496
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 »

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
Posts: 1575
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 »

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, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

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

Post by enclave »

or just dont use macros inside modify side... why would u need them... {GOLD..}
User avatar
Spannerbag
Posts: 493
Joined: December 18th, 2016, 6:14 pm
Location: Yes

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

Post by Spannerbag »

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!
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, 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