[0.10.2][cube] game.createentity and deserialization...

This subforum contains all the issues which we already resolved.
atehxx
Inserter
Inserter
Posts: 30
Joined: Sat Jun 21, 2014 9:35 pm
Contact:

[0.10.2][cube] game.createentity and deserialization...

Post by atehxx »

Hi,
I've been making mod for mass placing walls, turrents, poles, radars etc. just for practice and fun (yeah yeah I know...) :P
For this I use for now the function:

Code: Select all

function operation_Wall2(pStart, pFinish)
	local start=pStart or -900
	local finish=pFinish or 900
	local distance=30
	local radarDist=7

	local bigPolesCount=0
	if start > finish then
		bigPolesCount = start - finish
	else
		bigPolesCount = finish - start
	end
	bigPolesCount = math.floor(bigPolesCount / distance)
	local pos = {}
	local pos2 = {}

	for i=0, bigPolesCount, 1 do	-- top left to top right
		pos = {x=(start + (i * distance)), y = start}
		game.player.teleport{x=pos.x, y=pos.y-3} -- useless, it's all in one tick :)
		operation_removeEverything(pos, 20)

		-- Big Pole
		if (game.canplaceentity{name="big-electric-pole", position = pos}) then
			game.createentity{name = "big-electric-pole", position=pos, force=game.forces.player}
		end
		-- RADAR
		pos.x = pos.x-3
		if i%radarDist==0 and (game.canplaceentity{name="radar", position = pos}) then
			game.createentity{name = "radar", position=pos, force=game.forces.player}
		end
		pos.x = pos.x+3
	end
	-- more similar IFs here for other walls
end
function operation_removeEverything(position, radius)
	local toolArea = radius or 32
	local entities = game.findentities{{position.x - toolArea, position.y - toolArea}, {position.x + toolArea, position.y + toolArea}}
	for i, entity in ipairs(entities) do
		if entity ~= nil and entity.valid and entity.name~="player" then
			entity.destroy()
		end
	end
end
basicly, this function places big poles, and radars every 7 poles, and it's enough to trigger error.

When it's placed and I try to mine one of the new poles then game crashes.
When it's placed and I save the game, then try to load it, then I get Deserialization error, item id xxxx not exists...

Is there something I don't know about using createentity?
In other tries I didn't create poles, just radars, walls, turrets, and then placed poles by hand... and same error again when mining/loading save.
I even let the game running for some time (waited on debug console for all numbers to settle (Entities counters, connections counter), but it didn't help :( )

Any suggestions, or is it just some bug in game?
User avatar
cube
Former Staff
Former Staff
Posts: 1111
Joined: Tue Mar 05, 2013 8:14 pm
Contact:

Re: [0.10.2][cube] game.createentity and deserialization...

Post by cube »

Thank you for the report, this will be fixed for 0.10.3.
... your script also helped me find another (mostly unrelated) bug, so thanks again :-)
I have no idea what I'm talking about.
atehxx
Inserter
Inserter
Posts: 30
Joined: Sat Jun 21, 2014 9:35 pm
Contact:

Re: [0.10.2][cube] game.createentity and deserialization...

Post by atehxx »

Awesome!

I'm glad it helped to find other error too :)
By the way, is it intended that game.createentity can place many entities on exact same position? (I use IF canplaceentity to prevent this).
Rahjital
Filter Inserter
Filter Inserter
Posts: 435
Joined: Thu May 29, 2014 10:44 am
Contact:

Re: [0.10.2][cube] game.createentity and deserialization...

Post by Rahjital »

By the way, is it intended that game.createentity can place many entities on exact same position? (I use IF canplaceentity to prevent this).
As far as I can tell, it is, the canplaceentity and findnoncollidingposition methods are there if you want to make sure to place it in a valid position. Placing many entities in one place adds quite a bit of flexibility to modding.
Post Reply

Return to “Resolved Problems and Bugs”