Help reading darkness value

Place to get help with not working mods / modding interface.
Revolv
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon Jun 23, 2014 7:50 am
Contact:

Help reading darkness value

Post 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.
User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: Help reading darkness value

Post 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
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
Revolv
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon Jun 23, 2014 7:50 am
Contact:

Re: Help reading darkness value

Post 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.
Post Reply

Return to “Modding help”