Page 1 of 1

Help reading darkness value

Posted: Fri Dec 12, 2014 2:40 pm
by Revolv
I need help reading the darkness value on a unit spawner so I can disable spawning in the day. I understand that darkness is a read only property but I dont understand how to use it properly yet.

Code: Select all

result_units =
					 (function()
                     local res = {}
					 if  game.entity.darkness > 0.5   then
					 end
					 res[1] = {"1", {{0, 0.3}, {0.1, 0.1}, {0.2, 0},}}
					 res[2] = {"2", {{0.1, 0.1}, {0.2, 0.5}, {0.3, 0.3}, {0.4, 0},}}
					 res[3] = {"3", {{0.2, 0.1}, {0.3, 0.3}, {0.4, 0.5}, {0.5, 0.3}, {0.6, 0.2}, {0.7, 0.1}, {0.8, 0},}}
					 res[4] = {"4",{{0.3, 0.1}, {0.4, 0.2}, {0.5, 0.3}, {0.6, 0.4}, {0.7, 0.2}, {0.8, 0.1}, {0.9, 0},}}
					 res[5] = {"5", {{0.5, 0.1}, {0.6, 0.1}, {0.7, 0.15}, {0.8, 0.2}, {0.9, 0.3}, {1, 0.5},}}
                     return res
                   end)(),
Any help would be much appreciated.

Re: Help reading darkness value

Posted: Sat Dec 20, 2014 7:48 pm
by rk84
There are couple problems in that code. Shortly put, that function only runs once during prototype loading and there is no game to get darkness. It returns table. I don't know why they made it look like result_units could accept function as value.

Personally I also feel the code would have gameplay problem by making nests almost defenceless during day. I suggest you try using ontick event in control.lua and throw in setmulticommand

Re: Help reading darkness value

Posted: Mon Dec 22, 2014 5:15 am
by Revolv
Thank you, I had already been trying to use the onevent function but I'm still having issues.

Code: Select all

require "defines"

game.onevent(defines.events.onbuiltentity, function(event)
	if event.createdentity.type == "enemy" and game.darkness > 0.5 then
	game.createentity{name = "zombie", position= game.entity.position, force = game.forces.enemy}
	else game.entity.destroy
 end)
First of all, I need to find a way to either use game.createdentity.name to load all the individual enemy prototypes, but it just keeps giving me a syntax error any way i try it.
Second of all game.entity.destroy isn't working the way that i'm using it and I need to know the right way.
Ive been trying all over the modding forums but i'm still doing it wrong I guess, again any help is appriciated.