0ptera / Lighted-Poles-Plus

MIT License
2 stars 6 forks source link

1.7.3 Crashes on launch #9

Closed dodexahedron closed 2 years ago

dodexahedron commented 2 years ago

The GetItemFromRecipeResult function is broken in 1.7.3 and causes the game to crash on launch.

Some variables were renamed in some if statements but not in the loop they are contained in, causing the nil reference.

Here's the fixed version of the function:

-- check if recipe contains entry from Items
function GetItemFromRecipeResult(recipe)
  if recipe.result and pole_names[recipe.result] then
    return recipe.result
  end
  if recipe.normal and recipe.normal.result and pole_names[recipe.normal.result] then
    return recipe.normal.result
  end
  if recipe.expensive and recipe.expensive.result and pole_names[recipe.expensive.result] then
    return recipe.expensive.result
  end

  if recipe.results then
    for _, item in pairs(recipe.results) do
      if (not item.type or item.type == "item") and (item.name and pole_names[item.name] or pole_names[item[1]]) then
        return item.name or item[1]
      end
    end
  end
  if recipe.normal and recipe.normal.results then
    for _, item in pairs(recipe.normal.results) do
      if (not item.type or item.type == "item") and (item.name and pole_names[item.name] or pole_names[item[1]]) then
        return item.name or item[1]
      end
    end
  end
  if recipe.expensive and recipe.expensive.results then
    for _, item in pairs(recipe.expensive.results) do
      if (not item.type or item.type == "item") and (item.name and pole_names[item.name] or pole_names[item[1]]) then
        return item.name or item[1]
      end
    end
  end

  return nil
end