Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data.Util.Duplicate on normal/expensive recipes #140

Open
kryzeth opened this issue Jun 10, 2019 · 6 comments
Open

Data.Util.Duplicate on normal/expensive recipes #140

kryzeth opened this issue Jun 10, 2019 · 6 comments

Comments

@kryzeth
Copy link

kryzeth commented Jun 10, 2019

Not sure if I'm not using it right, but when I try using duplicate on a recipe that has normal/expensive variants, the result of those normal/expensive recipes are not set to the new name, but kept as the old name.

However, when using duplicate on a simple recipe that does not have difficulty defined, it works as I think is intended, where the result is set to the new name. Example code below:

local Data = require('__stdlib__/stdlib/data/data')
data:extend{(Data.Util.duplicate("recipe", "electric-mining-drill", "test-mining-drill"))}
error(serpent.block(data.raw.recipe["test-mining-drill"]))
@Nexela
Copy link
Collaborator

Nexela commented Jun 11, 2019

Data.Util.duplicate is old school code

See if this does what you want

Data(electric-mining-drill):copy('test-mining-drill)

No need to extend as Data handles all that

Keep in mind the Data Lib is still very much WIP (and looking for developers to assist!) and doesn't fully handle results in a lot of cases

@kryzeth
Copy link
Author

kryzeth commented Jun 11, 2019

Ah. That... completely changes how I have to do things. I wrote all of my current code on the assumption that I could edit the things before pushing them into the global table. At least I wasn't done yet, so rewriting everything won't be too bad, I suppose.

But yeah, Data.Util.duplicate was just the only thing I could find (and use) from the API. I still haven't figured out how to use the colon expressions, like the one you provided. Which also gives an error, but seems I just had to provide the data type (item, recipe, mining-drill, etc)

But it does seem to work as intended, setting the normal/expensive result properly.

@Nexela
Copy link
Collaborator

Nexela commented Jun 11, 2019

Lua is just table references, Data.raw is nothing special just a table. data:extend is just a function with very limited error checking that puts your table into data.raw in the correct spot. You can push whatever you want to it. and as long as when you are finished pushing to it it has everything it needs you won't have a problem.

The colon is just a shortcut syntax it passes the table (Data or more realistly the table created by Data as its first argument)
Using what you are familiar with data:extend({my_entity}) is just a shortcut for data.extend(data, {my_entity})

local test_recipe = Data('electric-mining-drill', 'recipe'):copy('test-mining-drill')
-- Its created, and pushed but that doesn't mean we have to be done with it.
test_recipe.energy_required = 200

There are even shortcuts if needed (ps just examples not even sure if it supports everything I put here)

Data('electric-mining-drill', 'recipe'):copy('test-mining-drill'):set_field('energy_required', 200):add_flag('hidden').change_this = 2

@Nexela
Copy link
Collaborator

Nexela commented Jun 11, 2019

Also Data can take a table in which case it doesnt need the second paramater as long as the table contains it (it also won't extend an already extended table, not that it matters)

Data(data.raw.recipe['electric-mining-drill']):copy('test-mining-drill') -- the copy will extend it.

@kryzeth
Copy link
Author

kryzeth commented Jun 11, 2019

Woah... that second example seems close to what I might need. So in that case, set_field is changing the value of 'energy_required', which is located within the newly created 'test-mining-drill' recipe? Hmm....

But wow, I never actually knew that. I just assumed data:extend({whatever}) was just the way Factorio added things. Thanks for the help! Also.. I also don't really use github, so not sure if I'm supposed to close this.. or something?

@Nexela
Copy link
Collaborator

Nexela commented Jun 11, 2019

We can leave it open, I might actually update duplicate :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants