Page 1 of 1

adding a property using table insert between se and mega furnace

Posted: Tue Mar 19, 2024 11:04 pm
by SANCHERIZZO
Hello guys! I need help. I want to write an addon that allows you to use a furnace in space for se. But the problem is that when trying to add the property se_allow_in_space = true, it does not work. I tried it using table insert. does not work. Thank you for your help.

Code: Select all

if data.raw["assembling-machine"]["mega-furnace"] then
  data.raw["assembling-machine"]["mega-furnace"].se_allow_in_space = true
end
Not working.

Code: Select all

table.insert (data.raw["assembling-machine"]["mega-furnace"],{{se_allow_in_space = true}})
not working too.

Code: Select all

data.raw["assembling-machine"]["mega-furnace"].se_allow_in_space = true
not working.

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 9:12 am
by Bilka
table.insert is intended for array-like tables, meaning a table with continuous numeric keys starting from 1. A prototype is not an array-like table. So data.raw["assembling-machine"]["mega-furnace"].se_allow_in_space = true is the correct syntax.

Have you checked whether the type and name you're using are correct? Usually furnaces have the furnace type, so data.raw["furnace"]["mega-furnace"].se_allow_in_space = true.

Or maybe "mega-furnace" is not the correct name for the prototype. You can check the prototype name and type by selecting the entity in-game and pressing SHIFT + CTRL + F to open the prototype explorer. It has rows for those two values.

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 9:29 am
by SANCHERIZZO
Bilka wrote:
Wed Mar 20, 2024 9:12 am
Or maybe "mega-furnace" is not the correct name for the prototype. You can check the prototype name and type by selecting the entity in-game and pressing SHIFT + CTRL + F to open the prototype explorer. It has rows for those two values.
in original mod yes is a furnace but krastorio2 or se changes type furnace on a assembling machine

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 9:31 am
by SANCHERIZZO
screenshot assembling machine

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 10:11 am
by Stringweasel
Are you sure your code is running? Is it placed in `data.lua`? Does it have an dependency on the mega-furnace mod?

To be sure you can change your code to:

Code: Select all

error("The code is running as expected")
if data.raw["assembling-machine"]["mega-furnace"] then
  data.raw["assembling-machine"]["mega-furnace"].se_allow_in_space = true
end

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 10:24 am
by SANCHERIZZO

Code: Select all

error("The code is running as expected")
please tell me where i see it, in game or log files?

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 10:34 am
by Stringweasel
It should crash your game while it's loading with that error message. If it's not then your code isn't running :)

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 10:35 am
by SANCHERIZZO
i add recipe category for check running my addon and it`s working, but se_allow_in_space = true not working.

Code: Select all

if data.raw["assembling-machine"]["mega-furnace"] then
  data.raw["assembling-machine"]["mega-furnace"].se_allow_in_space = true,
  table.insert(data.raw['assembling-machine']['mega-furnace'].crafting_categories,'kiln')
else
  error("The code is running not as expected")
end
may be need dependency for se?

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 10:42 am
by Stringweasel
SANCHERIZZO wrote:
Wed Mar 20, 2024 10:35 am
and it`s working
What do you mean? So did the code I provided crash? And you want it to crash, because that means the code was running. And once you verified that you can remove the `error(...)`.

Maybe a better clearer approach would be:

Code: Select all

log("[TEST] The code is running as expected")
if data.raw["assembling-machine"]["mega-furnace"] then
  log("[TEST] Found the entity prototype")
  data.raw["assembling-machine"]["mega-furnace"].se_allow_in_space = true
else
    log("[TEST] NOOO! COULD NOT FIND THE PROTOTYPE!")
end
You will find this log here https://wiki.factorio.com/Log_file

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 10:50 am
by SANCHERIZZO
i run you code, log

Code: Select all

8.247 Script @__5x slots__/data-final-fixes.lua:2: [TEST] The code is running as expected
8.247 Script @__5x slots__/data-final-fixes.lua:4: [TEST] Found the entity prototype
   

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 10:57 am
by Stringweasel
In what file did you place your code? It could be that it's running after SE does it's space checks. Safest is to add a dependency to SE as you mentioned. But it could be you placed your code in `data-final-fixes.lua` whereas better place might be `data-updates.lua`.

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 11:06 am
by SANCHERIZZO
Yes. You are right. data updates needed. I have question for the future. Can i change loadorder mod? Or tell me please where i can read about this. Thank you very much Stringweasel :)

Re: adding a property using table insert between se and mega furnace

Posted: Wed Mar 20, 2024 11:29 am
by Stringweasel
Happy to help :)

The documentation here explains the load order. And you'll see there the only way you should change it is by adding dependencies on other mods.