ID:2198918
 
(See the best response by Ter13.)
Problem description:
So I set out to create a simple little feature, where a generator will give a pulse of energy every second. This pulse of energy will go to the nearest cable within 1 tile of the generator, and travel along this cable and its corresponding pieces, until it either finds a machine to deposit the energy into, no other cable pieces or machines are found or the pulse value is reset by another pulse. The thing is, everything seems to be working hunkydory. Except, when I step away from the generator, energy is no longer transmitted, or when I stand over the cables, my bootleg autojoining system seems to die.

Code:
obj
Lab
Energy

EnergyWire
icon='Cables.dmi'
icon_state="pipe"
basestate="pipe"
power=0



Click()
basestate="pipe"
icon_state=basestate
switch(input(usr,"What direction should this wire point to?")in list("North","South","East","West"))
if("North")
dir=NORTH
direction="North"
if("South")
dir=SOUTH
direction="South"
if("East")
dir=EAST
direction="East"
if("West")
dir=WEST
direction="West"

De_energize()
//if(!origin) return
if(!activated) return
icon_state=basestate
activated=0
power=0
for(var/obj/Lab/Energy/EnergyWire/E in get_step(src,dir))
CableJoin(E)
E.De_energize()



Energize(origin)
if(!origin) return
if(activated) return
icon_state=basestate
icon_state="e[basestate]"
activated=1
//origin.power--
for(var/obj/Lab/Energy/E in get_step(src,dir))
if(!power) break
E.power+=power
power=0
if(istype(E,/obj/Lab/Energy/EnergyWire))
if(E.dir!=dir)
if(E.dir==get_dir(E,src))
break
CableJoin(E)
E.Energize(origin)
//icon_state=basestate






Generator
density=1
bound_width=32
bound_height=96
pixel_x=-32
icon='Lab Objects 3.dmi'
basestate="generator"
icon_state="generator-off"
power=1000
maxpower=3000
delay=10

Click()
if(usr in view(1,src))
if(!activated)
view(src)<<"The generator powers on"
Pulse(1)
else
Pulse(0)




proc
CableJoin(obj/E)
if(!E) return
switch(E.dir)
if(NORTH)
switch(dir)
if(EAST)
E.basestate="swcpipe2"
E.icon_state="[basestate]"
if(WEST)
E.basestate="secpipe2"
E.icon_state="[basestate]"
if(SOUTH)
switch(dir)
if(EAST)
E.basestate="nwcpipe2"
E.icon_state="[basestate]"
if(WEST)
E.basestate="necpipe2"
E.icon_state="[basestate]"
if(EAST)
switch(dir)
if(NORTH)
E.basestate="necpipe"
E.icon_state="[basestate]"
if(SOUTH)
E.basestate="secpipe"
E.icon_state="[basestate]"
if(WEST)
switch(dir)
if(SOUTH)
E.basestate="swcpipe"
E.icon_state="[basestate]"
if(NORTH)
E.basestate="nwcpipe"
E.icon_state="[basestate]"


Pulse(start = 1)
if(start)
icon_state="[basestate]-on"
activated=1
spawn while(activated && power)
for(var/obj/Lab/Energy/EnergyWire/E in oview(1))
if(power<=0) break
power--
E.power++
E.Energize(src)
spawn(5) E.De_energize()
sleep(delay)
else
activated=0
for(var/obj/Lab/Energy/EnergyWire/E in oview(1))
//if(power<=0) break
E.De_energize()
icon_state="[basestate]-off"
view(src)<<"The generator powers down"
Best response
oview(1) translates to oview(1,usr)

Press F1. Now type in oview() into the reference. Take a look at the arguments.

oview(Dist,Center=usr)

Center defaults to usr. Pulse is called from Click(), which means that usr will be a reference to the user that clicked the generator. That also means that oview() will be centered on the user's current location.

That's also why your bootleg autojoin thing is wigging out.

You need to change oview(1) to oview(1,src)
In response to Ter13
ah, thanks, everything's doing what it should now