Page 1 of 1

LuaItemStack was invalid

Posted: Fri Apr 22, 2016 10:36 pm
by Quazar
It's on my clipboard, might as well just ask... Homeworld crashes when the Seeder assembler thingy has no Tree Program input module in the inventory queue... It works as designed as long as there's one pending module (the first one is consumed to start the machine).

The code is:

Code: Select all

function Seeder:get_tree_type()
   if self.state.entity.is_crafting() then
      local inventory = self.state.entity.get_inventory(2)
      if inventory[1] then
         local tree_module = inventory[1].name
         return config.tree_types[tree_module]
      end
   end
   return nil
end
The error is "LuaItemStack API call when LuaItemStack was invalid" right after "if inventory[1] then" ... so it would seem to need some kind of check of is_empty or something?

Thanks!

Re: LuaItemStack was invalid

Posted: Fri Apr 22, 2016 10:39 pm
by prg

Re: LuaItemStack was invalid

Posted: Sat Apr 23, 2016 12:58 am
by Quazar
I'm about nowhere with mod dev... so it should be

Code: Select all

if inventory[1].valid_for_read() then
Is that correct? I appreciate the help.

My issue is the mod dev enviro, I'm struggling with issues like not having to restart the whole game to make a change, and being sure the change is active in the current environment, stuff like that. As it stands, once somebody says "yeah type that, it should work" I'll change the source, restart the game a few times, etc etc... this is all stuff I want to learn how to do properly, but just now I'd like to see Homeworld to the conclusion, you know?

Thanks!

Re: LuaItemStack was invalid

Posted: Sat Apr 23, 2016 9:14 am
by prg
valid_for_read is not a function, drop the ().

You don't need to restart all of Factorio if you only made a change to control.lua, just reloading the current game is enough. A complete restart is only required for data.lua related changes.

To produce debugging output to know you're running the right thing you can use print() and run the game in a terminal, or log() and check the log file.

Re: LuaItemStack was invalid

Posted: Sat Apr 23, 2016 9:45 pm
by Quazar
The fix worked like a charm, and even better... thank you for the mod dev clues!