Page 1 of 1

Unexpected results with data.raw

Posted: Sun Jun 09, 2019 12:45 am
by sinropa
Hello all!

I started work on a total conversion mod today, and I have to say I'm not off to a good start - ha!


So to get things up and running, I wrote a very trivial script to build a playground to dev in:

Code: Select all

--enable and remove mats from recipes
for k, v in pairs(data.raw.recipe) do

v.enabled = true
v.ingredients = {}

end
As you can see this simply iterates and blindly activates everything, or it should.

There are a few common recipes this doesn't hit.

So for example, this will unlock assembly machines 1 and 3 while 2 is missing. Console unlocking science brought an unmodified assembly 2 into the players crafting options.

So I'm looking for any possible cause that I am not hitting these items (at least not last, I suppose)

I am only running base beta and I've tried moving my script into data-final-fixes.

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 2:10 am
by DaveMcW

Code: Select all

for k, v in pairs(data.raw.recipe) do
  v.enabled = true
  if v.normal then v.normal.enabled = true end
  if v.expensive then v.expensive.enabled = true end
  v.ingredients = {}
end
I agree this is a horrible design and poorly documented.

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 3:40 am
by sinropa
Interesting.

Thank you for your reply. Is there a better dump of the games structures available or should I expect to do my own export?

I will give this a go, and again thanks for your time fixing the sample

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 7:59 am
by eradicator

Code: Select all

/c game.player.force.research_all_technologies()
/c game.player.cheat_mode = true

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 1:59 pm
by Qon
sinropa wrote: Sun Jun 09, 2019 3:40 am Is there a better dump of the games structures available or should I expect to do my own export?
There used to be one at the wiki for prototype definitions. You can still use that page of course. That's what you should use. It's just the raw dump that is missing from that page now.

All the info is also at https://github.com/wube/factorio-data (same info as in your Factorio directory). And it also has some comments and pages that are missing from the wiki. But it is the game files so it has comments but it isn't actual documentation of how to use it or what properties that are available but just were not set for the base games things.

If you want the entire thing as a searchable text file then I'll attach the dump that used to be available there for you. I'm using it because it's quick to search through in a text editor but it doesn't have any comments or documentation and you need to understand the structure to find the right things in it because it's a 200k lines document so you easily get way too many results from the wrong sections of the document. So

I would recommend that use the wiki primarily and the files in your Factorio/data directory (or the github, which can be easier to search through since it has Qonvenient multi-file search) if you want examples of how the base game defines the prototypes.

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 2:20 pm
by eradicator
Qon wrote: Sun Jun 09, 2019 1:59 pm If you want the entire thing as a searchable text file then I'll attach the dump that used to be available there for you. I'm using it because it's quick to search through in a text editor
I highly recommend using a text editor that can search through multiple files at once (like Notepad++, etcpp). Once the data is "dumped" it no longer contains information of how it got created. I.e. you lose all information about functions used to create wire connections, barrel recipes, etcpp. And even simple things like "x = 2/32" being converted to "x = 0.625", losing the meaning of "two pixels" and becoming a mere number. Ofc there are usecases where you want exactly this, but most of the time the original files will have better readability.

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 2:52 pm
by Bilka
Qon wrote: Sun Jun 09, 2019 1:59 pm
sinropa wrote: Sun Jun 09, 2019 3:40 am Is there a better dump of the games structures available or should I expect to do my own export?
There used to be one at the wiki for prototype definitions. You can still use that page of course. That's what you should use. It's just the raw dump that is missing from that page now.

If you want the entire thing as a searchable text file then I'll attach the dump that used to be available there for you.
Huh? There was never a data raw dump on that page. It has always been, and is still, linked on https://wiki.factorio.com/Data.raw.

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 3:16 pm
by eradicator
Bilka wrote: Sun Jun 09, 2019 2:52 pm Huh? There was never a data raw dump on that page. It has always been, and is still, linked on https://wiki.factorio.com/Data.raw.

Code: Select all

filename = "C:/Program Files (x86)/Steam/steamapps/common/Factorio/data/core/
Huh? Why are there absolute paths in a data.raw dump?

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 3:44 pm
by Bilka
eradicator wrote: Sun Jun 09, 2019 3:16 pm
Bilka wrote: Sun Jun 09, 2019 2:52 pm Huh? There was never a data raw dump on that page. It has always been, and is still, linked on https://wiki.factorio.com/Data.raw.

Code: Select all

filename = "C:/Program Files (x86)/Steam/steamapps/common/Factorio/data/core/
Huh? Why are there absolute paths in a data.raw dump?
Noise expressions. We had the same problem in the control stage, it was literally dumping full file paths into lua state. I'll look into getting it fixed, thank you for finding it.

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 5:14 pm
by Qon
eradicator wrote: Sun Jun 09, 2019 2:20 pm I highly recommend using a text editor that can search through multiple files at once
I do. Sublime text 3. But it's Qonvenient to use the raw file if you know its structure. Obviously I would use the multifile search feature for anything that requires it :)
Bilka wrote: Sun Jun 09, 2019 2:52 pm Huh? There was never a data raw dump on that page. It has always been, and is still, linked on https://wiki.factorio.com/Data.raw.
I got Qonfused. :D

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 10:04 pm
by sinropa
Yeah what I meant is that the online reference to data.raw did not mention the nested 'normal' and 'expensive' properties causing my loop to fail.

A complete dump, I would have seen that.

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 10:16 pm
by sinropa
Oh and thanks for the text dump, that should help if I need to dig up any more oddities.

Since its a total conversion, I'll be stomping on everything anyway

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 10:25 pm
by Bilka
sinropa wrote: Sun Jun 09, 2019 10:04 pm Yeah what I meant is that the online reference to data.raw did not mention the nested 'normal' and 'expensive' properties causing my loop to fail.

A complete dump, I would have seen that.
What reference are you using?

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 10:29 pm
by sinropa
In theory, normal and expensive should have been defined here, no?

https://lua-api.factorio.com/latest/Lua ... otype.html

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 10:33 pm
by Bilka
That's for runtime scripting. You should be looking at the data stage documentation for changing things in the data stage: https://wiki.factorio.com/Prototype/Recipe

Re: Unexpected results with data.raw

Posted: Sun Jun 09, 2019 10:48 pm
by sinropa
Thanks for the info. Those pages should help.

Re: Unexpected results with data.raw

Posted: Wed Jun 19, 2019 2:03 am
by sinropa
Well I finally got a chance last night to spend a night in the factorio modding sandbox.

Just wanted to come back and thank you all again for getting me started.

I've posted a day 1 beta of the playground project I started to poke at the API. Maybe someone will find it interesting as it changes the game problem a bit.

https://mods.factorio.com/mod/Singistics