Page 1 of 1

Help Converting to 0.12 please

Posted: Sat Jul 18, 2015 2:32 am
by TheSAguy
Hi,

I'm getting a game crashing error.
Not getting any error messages, just crash.

The crash is happening when I place an Alien Control Station.
I've attached a save, just before putting it down. Once I do, it crashes once it converts...

I have narrowed down the problem to the below lines of code. If I comment these two lines out (230 & 231) in the function Convert_Base, I don't get the error:
elseif enemy.type=="unit" then
table.insert(units, enemy)


The second possibility is lines 258 - 260

Code: Select all

function Convert_Base(base, died)
  local enemies=Get_Bounding_Box(base.position, NEConfig.UnitSearchDistance/global.minds.difficulty2)
  local units={}
  local hives={}
  local worms={}
  local count=0
  
  enemies = surface.find_entities(enemies)
  for i, enemy in ipairs(enemies) do
    if enemy.type=="turret" and enemy.force ==(game.forces.enemy) then
      table.insert(worms, enemy)
    elseif enemy.type=="unit-spawner" then
      table.insert(hives, enemy)
[color=#FF0000]    elseif enemy.type=="unit" then
      table.insert(units, enemy)[/color]
    end
  end
  count=#units+#hives+#worms
  if count~=0 then -- prevent empty random interval
    	
	writeDebug("The number of Units Converted: " .. count)	
  
  end
  if count~=0 and math.random(global.minds.difficulty2+math.sqrt(count))==1 then
    if died then table.insert(global.hiveminds, game.create_entity{name=base.name, position=base.position, force=game.player.force}) end
    for _, worm in pairs(worms) do worm.force=game.player.force writeDebug("Turret/Worm Converted") end
    for _, hive in pairs(hives) do hive.force=game.player.force table.insert(global.hiveminds, hive) end
    [color=#FF0000]for _, unit in pairs(units) do
      unit.force=game.player.force
      unit.set_command{type=defines.command.wander, distraction=defines.distraction.by_enemy}[/color]
      -- remove mind controlled biters in range from the minds table
      --so they aren't converted back into enemies when wandering away from the beacon
      for i, controlled in ipairs(global.minds) do
        writeDebug{unit, controlled}
        if unit ==(controlled) then
		--if unit.equals(controlled) then
          table.remove(global.minds, i)
          break
        end
      end
    end
  end
end


Thanks.

Re: Help Converting to 0.12 please

Posted: Sat Jul 18, 2015 10:06 am
by orzelek
It's this (line 11-12):

Code: Select all

event.createdentity
It also needs an _ - might not be in rename script.

Not sure where to go further - didn't use your mod :D

Re: Help Converting to 0.12 please

Posted: Sun Jul 19, 2015 1:56 am
by TheSAguy
Orzelek,
Found a major bug with your Factorio experience...
Evidence below:
orzelek wrote: Not sure where to go further - didn't use your mod :D
So I think I have most thinks working, except my Alien Control stations. I'm not getting any errors, but it's not converting any aliens. Could someone please take a look?

Thanks.

Re: Help Converting to 0.12 please

Posted: Sun Jul 19, 2015 9:59 pm
by TheSAguy
I think I've tracked town my problem. It's with inserting things into tables.

Here is my current code:

Code: Select all

    if event.created_entity.name == "AlienControlStation" then
		table.insert(global.beacons, entity)
		
	end
How should this be updated with v.12?
MOD attached to first post.

HELP appreciated!

Thanks.

Re: Help Converting to 0.12 please

Posted: Sun Jul 19, 2015 10:41 pm
by drs9999
Shouldn't:

Code: Select all

table.insert(global.beacons, entity)
rather be:

Code: Select all

table.insert(global.beacons, event.created_entity)
?

Re: Help Converting to 0.12 please

Posted: Mon Jul 20, 2015 12:08 am
by TheSAguy
Thanks drs9999,
Got that part fixed. Now having a problem with: "find_entities_filtered"

Getting this error:
Image

I have "find_entities_filtered" code in two places:
Line 166, triggers the error above

Code: Select all

local bases = game.find_entities_filtered{type="unit-spawner", area=Get_Bounding_Box(beacon.position, NEConfig.SpawnerSearchDistance)}
and line 203:

Code: Select all

if game.find_entities_filtered{name="AlienControlStation", area=Get_Bounding_Box(mind.position, NEConfig.UnitSearchDistance)}[1] then 
I know this is with the change that happend in v0.12 described below:

Code: Select all

Some commands moved from LuaGame to LuaSurface: get_pollution, can_place_entity, find_entity, find_entities, find_entities_filtered,
find_non_colliding_position, find_enemy_units, find_nearest_enemy, set_multi_command, create_entity, create_unit_group, build_enemy_base,
get_tile, get_tileproperties, set_tiles, pollute, get_chunks, is_chunk_generated
But don't exactly know what that means.

Besides fixing this code, is there a place I can go to learn a little more about all these changes??
I'm really not understanding the new "surface" thing...

Thanks for your help guys!

Re: Help Converting to 0.12 please

Posted: Mon Jul 20, 2015 12:14 am
by ratchetfreak
TheSAguy wrote:Thanks drs9999,
Got that part fixed. Now having a problem with: "find_entities_filtered"

Getting this error:
Image

I have "find_entities_filtered" code in two places:
Line 166, triggers the error above

Code: Select all

local bases = game.find_entities_filtered{type="unit-spawner", area=Get_Bounding_Box(beacon.position, NEConfig.SpawnerSearchDistance)}
and line 203:

Code: Select all

if game.find_entities_filtered{name="AlienControlStation", area=Get_Bounding_Box(mind.position, NEConfig.UnitSearchDistance)}[1] then 
I know this is with the change that happend in v0.12 described below:

Code: Select all

Some commands moved from LuaGame to LuaSurface: get_pollution, can_place_entity, find_entity, find_entities, find_entities_filtered,
find_non_colliding_position, find_enemy_units, find_nearest_enemy, set_multi_command, create_entity, create_unit_group, build_enemy_base,
get_tile, get_tileproperties, set_tiles, pollute, get_chunks, is_chunk_generated
But don't exactly know what that means.

Besides fixing this code, is there a place I can go to learn a little more about all these changes??
I'm really not understanding the new "surface" thing...

Thanks for your help guys!
in the event you should get a surface variable (sometimes from the entity the event is about)

otherwise the default surface is game.surfaces['nauvis'] (IIRC)

Re: Help Converting to 0.12 please

Posted: Mon Jul 20, 2015 12:55 am
by TheSAguy
Thanks,

Got the surface thing fixed (I think),
Now getting this:Image

I think I saw something about the "equils" being replaced by "=="

Code: Select all

if base.force.equals(game.forces.enemy) and math.random(global.minds.difficulty*2)==1 then
What's the new syntax?
Thanks.

Re: Help Converting to 0.12 please

Posted: Mon Jul 20, 2015 1:15 am
by ratchetfreak
just the == sign:

Code: Select all

    if base.force == game.forces.enemy and math.random(global.minds.difficulty*2)==1 then

Re: Help Converting to 0.12 please

Posted: Mon Jul 20, 2015 3:15 am
by TheSAguy
Okay,
Fixed that, but now I'm getting a game crash. No error massage....
Please see initial post.

Re: Help Converting to 0.12 please

Posted: Tue Jul 21, 2015 2:56 am
by TheSAguy
I think I've narrowed down what is causing my crash, but can't get it fixed.
Please see updated first post.

Thanks..

Re: Help Converting to 0.12 please

Posted: Tue Jul 21, 2015 7:27 am
by yeganer
I have no idea what your enemies variable contains BUT you could debug that thing by printing out your variables.

because i think you might be looping over something completely different and then comparing stuff and in the end doing something unexpected.

i think you might me interested in
surface.find_entities_filtered({...,force=game.forces.enemy})

In general i think it was a bad idea to rewrite your 1st post because it doesn't show your initial problem and others might have the same problem as you. now they won't find this.
Anyway, dump the table and look whats wrong with it.
Hint:
game.player.print(serpent.dump(table))

The last 2 calls in the crashlog are
Unit::releaseFromSpawner
and Unit::setCommand

so it might be your setcommand that crashes.
perhaps you could try to test that part of the code in the console?