Skip to content

tf_util-bugfix#10

Open
Mernom wants to merge 4 commits intoTubbles:masterfrom
Mernom:patch-1
Open

tf_util-bugfix#10
Mernom wants to merge 4 commits intoTubbles:masterfrom
Mernom:patch-1

Conversation

@Mernom
Copy link

@Mernom Mernom commented Jun 20, 2022

No description provided.

@Tubbles
Copy link
Owner

Tubbles commented Jun 20, 2022

Related to #8

@@ -1,4 +1,4 @@
local util = require("util")
local util = table.deepcopy ( require("util") )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit I am not very good with lua nor factorio modding, but does this not make a deepcopy only for the local variable? Or does this actually carry over to the, let's say, script/construction_drone.lua file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way tables work in Lua is that every variable with a table in it doesn't actually contain the table, it's merely a portal to the table. So every change made to it will apply to the original table, and every OTHER local variable that points at the same table as it will be able to see it. This is why you can do local belt = data.raw["transport-belt"]["express-transport-belt"]; belt.speed = 60, and it would apply to the original object held in the data table.

In the example you provide with scripts/construction_drone.lua, it never actually did see the modified tf_util table, even before I touched anything, since tf_util is executed during the DATA stage, which the script file is used during the CONTROL stage. No data beyond what factorio takes from the data table is transferred over.
The util in that file is defined in control.lua line 3.

@theisen1337
Copy link

I built these changes locally, but received errors when I ran other Klanon "based" mods. Running Hive_Mind_MitchPlay

This is the error I receive on startup with Hive_Mind.

image

I came back through this code base to change all "util" calls to local with deep_copy. Still receive the error on with Hive_mind, seems like there might be a deeper problem with Klanon "based" mods.

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

Successfully merging this pull request may close these issues.

3 participants