ID:170572
 
Lights
icon = "blah"
Icon_state = [lights]
world/var/lights = "on"


would that work? for if you change the lights var to on or off it changes all the icon states of that icon in the world
Strawgate wrote:
> Lights
> icon = "blah"
> Icon_state = [lights]
> world/var/lights = "on"
>

would that work? for if you change the lights var to on or off it changes all the icon states of that icon in the world

Nope. You have to manually change all of the lights' icon_state. Something like this:
obj/Lights/
icon = 'blah.dmi'
icon_state = "on"
world/
var/lights_on = 1
proc/Light_Switch()
var/nextstate = ""
var/obj/Lights/L
lights_on = !lights_on
if(lights_on) nextstate = "on"
else nextstate = "off"

for(L in world)
L.icon_state = nextstate

All we do is determine, based on the world var lights_on, what the icon_state of the lights should be, then loop through all the lights in the world and set their icon state. Then we change our variable.
In response to Nova2000
i understand that but how does it work?
In response to Nova2000
Nove, first of all, you really don't need those trailing slashes after everything. Second, the if(lights_on) line kind of nullifies the point of lights_on=!lights_on. However, you can still avoid an if() check by using the ? operator:

obj/Lights
icon = 'blah.dmi'
icon_state = "on"
world
var/lights_on = 1
proc/Light_Switch()
var/nextstate
lights_on = !lights_on
lights_on ? nextstate="on" : nextstate="off"

for(var/obj/Lights/L in world)
L.icon_state = nextstate


Still, there's not really even a reason to have nextstate, and there's also no reason to define it under world anyway:

obj/Lights
icon = 'lights.dmi'
icon_state = "on"

var/lights_on = 1

proc/Light_Switch()
lights_on = !lights_on
for(var/obj/Lights/L in world)
lights_on ? L.icon_state="on" : L.icon_state="off"
In response to Strawgate
Strawgate wrote:
i understand that but how does it work?

Basically, the line, lights_on=!lights_on means, in english, "set lights_on to the opposite of its current value". obviously, this statement only makes sense for boolean variables (boolean variables are variables that are always either set to 1 or set to 0; TRUE or FASLE). atom.density, for example, is a boolean variable.
In response to Nova2000
it doesnt work for turning the lights off how would i make them go off? it says cant read null.luminosity
In response to Strawgate
Luminosity? You didn't show where you were changing luminosity...

In any case, "Cannot read null.whatever" errors are caused by the thing before the ".whatever" being null. So you just have to work out why it's null.

Please show the proc where the error occurs.