LuaItemStack was invalid

Place to get help with not working mods / modding interface.
Post Reply
Quazar
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Sat Mar 26, 2016 4:12 pm
Contact:

LuaItemStack was invalid

Post 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!

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: LuaItemStack was invalid

Post by prg »

Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Quazar
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Sat Mar 26, 2016 4:12 pm
Contact:

Re: LuaItemStack was invalid

Post 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!

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: LuaItemStack was invalid

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Quazar
Long Handed Inserter
Long Handed Inserter
Posts: 51
Joined: Sat Mar 26, 2016 4:12 pm
Contact:

Re: LuaItemStack was invalid

Post by Quazar »

The fix worked like a charm, and even better... thank you for the mod dev clues!

Post Reply

Return to “Modding help”