Instructions for Overriding World Conquest enemy army array Unclear

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
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Instructions for Overriding World Conquest enemy army array Unclear

Post by Lord-Knightmare »

After 2-3 weeks of trying...I have finally arrived here with my problem. :augh:

In the mainline campaign directory, there is this file which states that I can define my own enemy army array and the one in the campaign is default case/fallback.

Anyways, I made my own: Here

The expected outcome should have been some success but all I got was this:

Code: Select all

20220112 03:40:22 error scripting/lua: campaigns/World_Conquest/lua/campaign/enemy.lua:252: attempt to perform arithmetic on a nil value
stack traceback:
	campaigns/World_Conquest/lua/campaign/enemy.lua:252: in local 'cmd'
	lua/wml-utils.lua:144: in field 'handle_event_commands'
	lua/wml-flow.lua:5: in function <lua/wml-flow.lua:4>
I opened the inspector and saw the array was there in the variables, so maybe it's the next step which is throwing the error?

Thus, I ask: What am I doing wrong? Or am I missing something? Or, are these modding instructions incomplete (if so, it should be filed as an issue)?
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Instructions for Overriding World Conquest enemy army array Unclear

Post by vghetto »

Well, go to line 252 and see what's going on.
Are you sure WC's lua can access WoL's units path?
I would also remove the line id="wc2_init_enemy".
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Instructions for Overriding World Conquest enemy army array Unclear

Post by Lord-Knightmare »

vghetto wrote: January 12th, 2022, 9:27 am Well, go to line 252 and see what's going on.
Are you sure WC's lua can access WoL's units path?
I would also remove the line id="wc2_init_enemy".

Code: Select all

local enemy_type_id = wc2_utils.pick_random("wc2_enemy_army.factions_available") - 1
Seems wc2_utils.pick_random("wc2_enemy_army.factions_available") isn't being created so it's a nil...I wonder what's the cause...? would be nice if a lua expert commented here...or maybe move this to Lua Labs since it seems more Lua than WML, despite having both...?
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Instructions for Overriding World Conquest enemy army array Unclear

Post by Celtic_Minstrel »

The wc2_utils.pick_random function is defined on line 28 of utils.lua, and in this specific call, you can see that str is non-nil (so the outermost if is entered) and generator is nil (so the inner if is not entered).

That means that the only way for it to return nil would be if array[index] is nil, and as far as I can tell, the only way for that to happen would be that array has no elements… and from what I can tell, that can only happen if the variable wc2_enemy_army.factions_available is either nil or an empty string.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Instructions for Overriding World Conquest enemy army array Unclear

Post by Lord-Knightmare »

Celtic_Minstrel wrote: January 20th, 2022, 12:26 am The wc2_utils.pick_random function is defined on line 28 of utils.lua, and in this specific call, you can see that str is non-nil (so the outermost if is entered) and generator is nil (so the inner if is not entered).

That means that the only way for it to return nil would be if array[index] is nil, and as far as I can tell, the only way for that to happen would be that array has no elements… and from what I can tell, that can only happen if the variable wc2_enemy_army.factions_available is either nil or an empty string.
I have later found out (big thank you to Soliton) that the modding instructions is half done. It's missing some code which counts the groups and creates factions_available and allies_available keys for the array. The fallback has the code so it didn't face the problem.

I got around this problem by hardcoding the two missing keys and got it to work.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Post Reply