ID:2232578
 
(See the best response by Nadrew.)
Code:
..()
var obj/Lighting/Light_Source/L
var obj/Lighting/Darkness/D
var list/LS
. = view(7,src)
for(D in .)
LS = view(7,D)
var A = 210
for(L in LS)
A -= get_dist(D,L) * 30
D.alpha = 210 - A


Problem description:

The lighting system doesn't seem to be acting right and I have no clue why, was hoping to get some insight.

The above code is ran upon each light baked onto the map and finds all the darkness tiles within view and searchs their view for lights to allow lighting to overlap smoothly but this seems to be the results as it's the only light on and notice to the right how it's dark.

Best response
Tiny screenshot is entirely useless, but your best bet is probably adding some debugging text to each step to see where things aren't going as expected. The code you posted doesn't really mean much on its own.
proc/SpawnDarkness()
var X = world.maxx, A
var Y = world.maxy, B
var Z = world.maxz, C
for(A = 1 to X)
for(B = 1 to Y)
for(C = 1 to Z)
new/obj/Lighting/Darkness(locate(A,B,C))

mob
sight = SEE_BLACKNESS

obj/Lighting
icon = 'light.dmi'
layer = 444
Darkness
Click()
var/obj/Lighting/Light_Source/LS = locate(/obj/Lighting/Light_Source) in loc.contents
if(LS)
LS.BOOP()
world.name = "xy: [x],[y] -> [alpha]"
Light_Source
icon = 'tiles.dmi'
icon_state = "light"
proc/BOOP()
..()
var obj/Lighting/Light_Source/L
var obj/Lighting/Darkness/D
var list/LS
. = view(7,src)
var i = 0
for(D in .)
LS = view(7,D)
var A = 210
for(L in LS)
i++
A -= get_dist(D,L) * 30
A = 210 - A
D.alpha = A ? A : 0
world.log << "i = [i]"


Okay so, SpawnDarkness() is called upon world/New() where it generates darkness on the map during runtime.

obj/Lighting/Light_Source are literally the lights placed on the map in the map editor.

At the moment they only turn on when clicked because of the issue posted at the beginning of this thread.

When the light source is clicked it loops through all the darkness within 7 tiles of the light source and then loops through all the light sources within view of that darkness so that overlapping lighting is possible and looks smooth.

The above however doesn't seem to be working as planned as I wouldn't really know any other way to reproduce this kind of lighting as the walls in this project are destructible so the lighting needs to update when needed.

Apologies about the delay, I don't have access to a real computer anymore. Just looking over the code, nothing really stands out as a glaring problem outside of the obvious stuff like, why are you using the return value of BOOP() for looping but never actually using those results? You don't really need to be setting "." in that proc.

Another thing you could try is storing the light sources all in their own list, looping over that and using get_dist() to see if it's where you need it to be (and maybe a viewers() check).

But like I said above, your best bet is adding debugging text all over the place and seeing exactly where the process is collapsing, I see you've got some stuff for debugging in there, but you could use more like the values of "A" in your nested loop, and things of that nature.
Nevermind I found a solution :P



This was the fix for those interested.

Farther in the type tree I'd make D & LS object variables so that they aren't needed to be created constantly.

During world/New() I could also check for LS's in the Darkness view once during startup so that the list need not be created each time as well. Needs to be dynamic.

obj/proc/UpdateLights()
. = view(7,src)
var obj/Lighting/Darkness/D
var obj/Lighting/Light_Source/LS
for(D in .)
. = view(7,D)
var AL = 210
for(LS in .)
AL -= 210 - (get_dist(D,LS) * 30)
D.alpha = AL