[micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

[micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

Post by WhiteWolf »

Hello,

I'm trying to make some scattered animals behave like animals with the [micro_ai] ai_type=forest_animals setting. Here's the code:

Code: Select all

[event]
    name=prestart
    
		[micro_ai]
			ca_id=jonadiszno
			side=3
			action=add
			ai_type=forest_animals
			rabbit_type="Rabbit TRS"
			deer_type="Stag TRS"
			tusker_type="Horse TRS,Boar TRS"
			tusklet_type="Chicken TRS,Pig TRS"
			rabbit_hole_img="scenery/dirt.png"
			[filter_location]
				[not]
					x=1-30
					y=1-11
				[/not]
			[/filter_location]
		[/micro_ai]
[/event]

The unit types are valid, and the scattered units are on the map. Yet, each time it's side 3's turn, after a few moves, this error happens:
error
error
What am I doing wrong?


EDIT:
These are the lines the error is pointing to in ca_forest_animals_move.cfg:

Code: Select all

    -- If cfg.rabbit_hole_img is set, only items with that image or halo count as holes
    local holes
    if cfg.rabbit_hole_img then
        for _,item in ipairs(all_items) do
            if (item.image == cfg.rabbit_hole_img) or (item.halo == cfg.rabbit_hole_img) then
                table.insert(holes, item)
            end
        end
    else
        holes = all_items
    end
Apparently it doesn't see the items? There are numerous

Code: Select all

[item]
     x,y=...
     image=scenery/dirt.png
[/item]
items on the map, I don't see why the micro_ai doesn't find them.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
User avatar
Celtic_Minstrel
Developer
Posts: 2214
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

Post by Celtic_Minstrel »

I think the fix would be to write local holes = {} on the second line of your posted code snippet (naturally that would be a bug in the AI if so, but you can make the change yourself for a quick test).
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: [micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

Post by mattsc »

Yes, that's it, and it is already fixed, but only from Wesnoth 1.14.6 on, while it looks like you're using 1.14.5.
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: [micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

Post by WhiteWolf »

Oh, I see. Yes, sadly 1.14.5 is still the newest with my linux distribution, and I'm not great at compiling from source.
Guess I'll use an #ifver for the custom rabbit hole then :)
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
User avatar
Ravana
Forum Moderator
Posts: 3004
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

Post by Ravana »

It is Lua change, no compiling needed. You can open the file and change it yourself.

That is if you need it for yourself, for other players if you want to support lower versions you need workarounds.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: [micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

Post by mattsc »

Also, since the entire Micro AI is written in Lua, you could add a local, fixed version of the MAI to your campaign and use that. Then it becomes independent of the version a player uses. Might not be worth the effort though.
User avatar
EarthCake
Posts: 377
Joined: March 29th, 2019, 1:57 pm
Location: The Wall

Re: [micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

Post by EarthCake »

WhiteWolf wrote: August 28th, 2019, 6:36 pm Oh, I see. Yes, sadly 1.14.5 is still the newest with my linux distribution, and I'm not great at compiling from source.
Guess I'll use an #ifver for the custom rabbit hole then :)
You can install 1.14.7 via flatpak if you are using Ubuntu. http://ubuntuhandbook.org/index.php/201 ... o-install/
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: [micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

Post by WhiteWolf »

I already handfixed it here, but that's the point, for if anyone is still using 1.14.5 or older for some reason, it'd be broken for them, that's why I decided to use an ifver condition. :) It's also less effort than trying to include the entire MAI in the campaign. But that's another option, could be done some time later. Thanks :)
EarthCake wrote: August 28th, 2019, 7:54 pm You can install 1.14.7 via flatpak if you are using Ubuntu. http://ubuntuhandbook.org/index.php/201 ... o-install/
It's Debian 8 sadly.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: [micro_ai] error: bad argument #1 to 'insert' (table expected, got nil)

Post by Pentarctagon »

Flatpak is supposed to be distro-agnostic, so it can be installed on Debian as well, depending on if Debian 8 supports it.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
Post Reply