Adding entry to table, working?

Place to get help with not working mods / modding interface.
slay_mithos
Fast Inserter
Fast Inserter
Posts: 204
Joined: Tue Feb 25, 2014 7:22 am
Contact:

Adding entry to table, working?

Post by slay_mithos »

Hello,

I am trying to fix a problem caused by the fact that both Dytech and MoCombat completely redefine the entire bitter spawner's "result_units", just to add their bitter(s) to the list. Well, dytech redefines the spawner entirely instead, but that changes very little to the problem.

The problem is that the changes of the first to load (in that case dytech) are overriden.


A quick search around lua's wiki about tables gave me a pretty easy answer, but I need to make sure it is actually working or not.
The 'solution' is obviously

Code: Select all

table.insert(data.raw["unit-spawner"]["biter-spawner"].result_units,
	{"medium-spitter", 0.35});
My question now is how to check if this actually worked or not.

My guess so far went into:

Code: Select all

remote.addinterface('testing', {
	get = function ()
		//Try to get the property
game.player.print(game.entityprototypes["biter-spawner"].result_units)
return "empty"
	end
})
I really don't have a clue on how to check the values in the table during the game, to verify if the line has been added or not.
User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 245
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: Adding entry to table, working?

Post by ludsoe »

Heres some Untested code, It should work assuming i did it correctly. If it doesn't it should be a quick fix on your part.

Code: Select all

function PrintTable(Table)
	for i,d in pairs(Table) do
		if type(d) == "table" then
			PrintTable(d)
		else
			game.player.print(i.." : "..tostring(d))
		end
	end
end
remote.addinterface('testing', {
PrintTable(game.entityprototypes["biter-spawner"].result_units)
})
Also thanks for bringing up the fact, Mocombat overrides Dytech's spawner changes. Ill be adding proper support later.
kovarex
Factorio Staff
Factorio Staff
Posts: 8293
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Adding entry to table, working?

Post by kovarex »

This is exactly the kind of trouble that emerges from the rewrite instead of modify approach I was warning against.
So yes, inserting to the table is better, I would also advice inserting it before the big biter (after the medium), so it is positioned correctly evolution wise.

Reading result_units ingame using LuaEntityPrototype is not possible currently
slay_mithos
Fast Inserter
Fast Inserter
Posts: 204
Joined: Tue Feb 25, 2014 7:22 am
Contact:

Re: Adding entry to table, working?

Post by slay_mithos »

Yep, I found that out now.

Also, I tried to load a map that has high evolution factor (high enough to spawn big bitters and the red ones from dytech), but none of your spitters spawned once I cleaned the first wave that had spawned before my change.

Sadly, it seems to mean that either the insert is not done properly, or that the probability reaching 1 before that line, it is never spawned.
I sure hope that it's the first, because the second option would mean that the probabilities in that table are working very differently compared to the ones for multiple outputs on resources (where you can have multiple results to 1 with no trouble at all, all probability being calculated separately).


From what you are saying, it means that I have to insert it between medium and big, so I'll try that.

On that note, wouldn't it be "better" to place an "evolution-factor" line into the bitter entities instead of doing it depending on the order in the list?
It would make it easier for mods to add their bitters to the list, without it potentially pushing down other bitter types.

EDIT:
The easy way would be (not certain if it should be 2 or 3, the documentations tends to say that 1 places the entry in first position, so 3 here):

Code: Select all

table.insert(data.raw["unit-spawner"]["biter-spawner"].result_units, 3, {"medium-spitter", 0.35})
But that's assuming that the medium bitter would still be at that place in the table.

The correct way would be something like:

Code: Select all

function get_key_for_value( t, value )
	for k,v in pairs(t) do
		if v==value then
			return k
		end
	end
	return nil
end
local big_bitter = get_key_for_value(data.raw["unit-spawner"]["biter-spawner"].result_units, "big-bitter"
table.insert(data.raw["unit-spawner"]["biter-spawner"].result_units, big_bitter, {"medium-spitter", 0.35})
EDIT2: OK, please disregard the second part of the first edit, it does not work^^.

EDIT 3: I'm not completely certain, but it seems that adding it between medium and big bitters makes the "evolution" regress by quite a bit, because I previously had big and the one after that, and I now only stop at the spitter (same place in the list as the big previously).

My guess is that the number affects the required "evolution", and a high number like that changes the balance quite a lot, so it might need to be lowered to 0.15 or 0.20 at most.
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: Adding entry to table, working?

Post by Dysoch »

Ill uploaded a new version today with only the lines edited i need ;) ( only for biter-spawner, rest will come soon)
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
Post Reply

Return to “Modding help”