Lua error

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

Moderator: Forum Moderators

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

Lua error

Post by Spannerbag »

Hi,
During playtesting got this error, I use the goto micro_ai a lot in this scenario and it's never given me any problems.

Code: Select all

error scripting/lua: ai/micro_ais/cas/ca_goto.lua:211: attempt to index a nil value (local 'closest_hex')
stack traceback:
	ai/micro_ais/cas/ca_goto.lua:211: in field 'execution'
	[string "local self, params, data, filter_own = ......"]:2: in main chunk
The relevant lua is

Code: Select all

    -- If any of the non-standard path finding options were used,
    -- we need to pick the farthest reachable hex along that path
    -- For simplicity, we do it for all types of pathfinding here,
    -- rather than using ai_helper.next_hop for standard pathfinding
    -- Also, straight-line does not produce a path, so we do that first
    if not best_path then
        best_path = AH.find_path_with_avoid(best_unit, closest_hex[1], closest_hex[2], GO_avoid_map)   -- *** LINE 211 ***
    end
I am continually tweaking code but haven't changed the micro_ai stuff recently.
If I can reproduce it I'll post details here.
Apologies but when error came on screen I was looking elsewhere and don't have any more details.

If it is likely to be due to something I've done I'd appreciate any pointers?
The last change I made (and was testing) was a tweak to terrain changes (there are extensive terrain changes throughout in this scenario) but this never makes terrain impassable. Even movement costs are hardly changed and terrain changes events are: name=new turn,side 1 turn end,side 4 turn end.

Any suggestions greatfully received!
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
Ravana
Forum Moderator
Posts: 3242
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Lua error

Post by Ravana »

Since closest_hex is undefined you would have to find how it is assigned. From first review easiest way to explain it would be having units empty, since closest_hex is assigned only during loop over units.
User avatar
Spannerbag
Posts: 702
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Lua error

Post by Spannerbag »

Thanks for the suggestion, much 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