I encounter a normal error with lightning while building a world in voidrpg. iam trying to activate lightning.

some code here
;VoidRPG World Editor
Dim HMAP#(1024,1024)
;World mesh globals.
Global wx=1024,wz=1024
Dim verts(64,64,8) ; 8 layers per square
Global camera
Graphics3D 1280,800,32,1
SetBuffer BackBuffer()
camera=CreateCamera()
CameraViewport camera,0,0,1280,800
CameraRange camera,0.01,1000
PositionEntity camera,32,256,32
light=CreateLight()
sphere=CreateSphere(8,light)
ScaleEntity sphere,100,100,100
rot=CreateCube()
EntityParent light,rot
PositionEntity light,0,1000,0
map=LoadImage("hmap.bmp")
;Load in the height data into world matrix
width=128
height=128
For z=1 To height
For x=1 To width
h#=0
For x1=-2 To 2
For z1=-2 To 2
H#=h#+(ReadPixel(x+z1,z+z1,ImageBuffer(map)) And 255)
Next
Next
h#=h#/24.0
HMAP(x,z)=h#
Next
Print "Completed line "+z+" of "+height
Next
;CreateWorld
For z=1 To 128 Step 63
For x=1 To 128 Step 63
CreatePlane(x,z)
Next
Next
While Not KeyHit(1)
TurnEntity rot,1,1,1
UpdateWorld()
RenderWorld()
camera_handling()
Flip
Wend
Function camera_handling()
If KeyDown(17);W
MoveEntity camera,0,0,0.1
End If
If KeyDown(31)
MoveEntity camera,0,0,-0.1
End If
If KeyDown(30)
MoveEntity camera,-0.1,0,0
End If
If KeyDown(32)
MoveEntity camera,0.1,0,0
End If
smx#=MouseXSpeed()/15
smy#=MouseYSpeed()/15
MoveMouse 320,200
TurnEntity camera,smy#,-smx#,0
RotateEntity camera,EntityPitch(camera),EntityYaw(camera),0
TranslateEntity camera,0,-0.1,0
y#=BilinearInterpValue# ( Float(EntityX(camera)) ,Float(EntityZ(camera)) )
If y#+1.5>EntityY#(camera)
PositionEntity camera,EntityX(camera),y#+1.5,EntityZ(camera)
jumps=0
yspeed#=0
End If
End Function
Function CreatePlane(xoffs,zoffs)
;Creates a matrix
mesh=CreateMesh()
surface=CreateSurface(mesh)
;firstvert=AddVertex (surface,0,0,0) ;A dummi verts sens i begin reading mem from 1 and above.
For z=1 To 64
For x=1 To 64
vert=AddVertex(surface,x+xoffs,HMAP#(x+xoffs,z+zoffs),z+zoffs,x+xoffs,z+zoffs) ; Ads a vertex
verts(x,z,1)=vert ;Put the vertex on place.
Next
Next
;Addtriangles to surface.
For z=1 To 63
For x=1 To 63
AddTriangle surface,verts(x,z,1),verts(x,z+1,1),verts(x+1,z+1,1)
AddTriangle surface,verts(x,z,1),verts(x+1,z+1,1),verts(x+1,z,1)
Next
Next
;Update the normals
MESHnormals( mesh )
End Function
;Functions not created by me
Function BilinearInterpValue# ( x1# , y1# )
X_low = Int ( Floor(x1) )
X_hi = Int ( Ceil (x1) )
Y_low = Int ( Floor(y1) )
Y_hi = Int ( Ceil (y1) )
;Kepp things in bound :)
If X_low < 0 Or X_low > WX Then x_low=0
If X_hi < 0 Or X_hi > WX Then x_hi=0
If Y_low < 0 Or Y_low > WZ Then Y_low=0
If Y_hi < 0 Or Y_hi > WZ Then Y_hi=0
x_per# = x1 - x_low
y_per# = y1 - y_low
p00# = HMAP# ( x_low , y_low )
p10# = HMAP# ( x_hi , y_low )
p01# = HMAP# ( x_low , y_hi )
p11# = HMAP# ( x_hi , y_hi )
i1# = LinearInterpolate#(p00#,p10#,x_per#)
i2# = LinearInterpolate#(p01#,p11#,x_per#)
Return LinearInterpolate#(i1#,i2#,y_per#)
End Function
;thanks too gabrielknight74. philings2@...
Function LinearInterpolate#(a#,b#,x#)
Return a#+(b#-a#)*x#
End Function
Function MESHnormals( tmesh )
For l = 1 To CountSurfaces(tmesh )
s = GetSurface( tmesh , l )
For t = 0 To CountTriangles( s )-1
v0 = TriangleVertex( s, t, 0 )
v1 = TriangleVertex( s, t, 1 )
v2 = TriangleVertex( s, t, 2 )
ax# = VertexX( s, v1 ) - VertexX( s, v0 )
ay# = VertexY( s, v1 ) - VertexY( s, v0 )
az# = VertexZ( s, v1 ) - VertexZ( s, v0 )
bx# = VertexX( s, v2 ) - VertexX( s, v1 )
by# = VertexY( s, v2 ) - VertexY( s, v1 )
bz# = VertexZ( s, v2 ) - VertexZ( s, v1 )
Nx# = ( ay * bz ) - ( az * by )
Ny# = ( az * bx ) - ( ax * bz )
Nz# = ( ax * by ) - ( ay * bx )
Ns# = Sqr( Nx * Nx + Ny*Ny + Nz*Nz )
Nx = Nx / Ns
Ny = Ny / Ns
Nz = Nz / Ns
For v = v0 To v2
VertexNormal s, v, Nx, Ny, Nz
Next
Next
Next
End Function

some code here
;VoidRPG World Editor
Dim HMAP#(1024,1024)
;World mesh globals.
Global wx=1024,wz=1024
Dim verts(64,64,8) ; 8 layers per square
Global camera
Graphics3D 1280,800,32,1
SetBuffer BackBuffer()
camera=CreateCamera()
CameraViewport camera,0,0,1280,800
CameraRange camera,0.01,1000
PositionEntity camera,32,256,32
light=CreateLight()
sphere=CreateSphere(8,light)
ScaleEntity sphere,100,100,100
rot=CreateCube()
EntityParent light,rot
PositionEntity light,0,1000,0
map=LoadImage("hmap.bmp")
;Load in the height data into world matrix
width=128
height=128
For z=1 To height
For x=1 To width
h#=0
For x1=-2 To 2
For z1=-2 To 2
H#=h#+(ReadPixel(x+z1,z+z1,ImageBuffer(map)) And 255)
Next
Next
h#=h#/24.0
HMAP(x,z)=h#
Next
Print "Completed line "+z+" of "+height
Next
;CreateWorld
For z=1 To 128 Step 63
For x=1 To 128 Step 63
CreatePlane(x,z)
Next
Next
While Not KeyHit(1)
TurnEntity rot,1,1,1
UpdateWorld()
RenderWorld()
camera_handling()
Flip
Wend
Function camera_handling()
If KeyDown(17);W
MoveEntity camera,0,0,0.1
End If
If KeyDown(31)
MoveEntity camera,0,0,-0.1
End If
If KeyDown(30)
MoveEntity camera,-0.1,0,0
End If
If KeyDown(32)
MoveEntity camera,0.1,0,0
End If
smx#=MouseXSpeed()/15
smy#=MouseYSpeed()/15
MoveMouse 320,200
TurnEntity camera,smy#,-smx#,0
RotateEntity camera,EntityPitch(camera),EntityYaw(camera),0
TranslateEntity camera,0,-0.1,0
y#=BilinearInterpValue# ( Float(EntityX(camera)) ,Float(EntityZ(camera)) )
If y#+1.5>EntityY#(camera)
PositionEntity camera,EntityX(camera),y#+1.5,EntityZ(camera)
jumps=0
yspeed#=0
End If
End Function
Function CreatePlane(xoffs,zoffs)
;Creates a matrix
mesh=CreateMesh()
surface=CreateSurface(mesh)
;firstvert=AddVertex (surface,0,0,0) ;A dummi verts sens i begin reading mem from 1 and above.
For z=1 To 64
For x=1 To 64
vert=AddVertex(surface,x+xoffs,HMAP#(x+xoffs,z+zoffs),z+zoffs,x+xoffs,z+zoffs) ; Ads a vertex
verts(x,z,1)=vert ;Put the vertex on place.
Next
Next
;Addtriangles to surface.
For z=1 To 63
For x=1 To 63
AddTriangle surface,verts(x,z,1),verts(x,z+1,1),verts(x+1,z+1,1)
AddTriangle surface,verts(x,z,1),verts(x+1,z+1,1),verts(x+1,z,1)
Next
Next
;Update the normals
MESHnormals( mesh )
End Function
;Functions not created by me
Function BilinearInterpValue# ( x1# , y1# )
X_low = Int ( Floor(x1) )
X_hi = Int ( Ceil (x1) )
Y_low = Int ( Floor(y1) )
Y_hi = Int ( Ceil (y1) )
;Kepp things in bound :)
If X_low < 0 Or X_low > WX Then x_low=0
If X_hi < 0 Or X_hi > WX Then x_hi=0
If Y_low < 0 Or Y_low > WZ Then Y_low=0
If Y_hi < 0 Or Y_hi > WZ Then Y_hi=0
x_per# = x1 - x_low
y_per# = y1 - y_low
p00# = HMAP# ( x_low , y_low )
p10# = HMAP# ( x_hi , y_low )
p01# = HMAP# ( x_low , y_hi )
p11# = HMAP# ( x_hi , y_hi )
i1# = LinearInterpolate#(p00#,p10#,x_per#)
i2# = LinearInterpolate#(p01#,p11#,x_per#)
Return LinearInterpolate#(i1#,i2#,y_per#)
End Function
;thanks too gabrielknight74. philings2@...
Function LinearInterpolate#(a#,b#,x#)
Return a#+(b#-a#)*x#
End Function
Function MESHnormals( tmesh )
For l = 1 To CountSurfaces(tmesh )
s = GetSurface( tmesh , l )
For t = 0 To CountTriangles( s )-1
v0 = TriangleVertex( s, t, 0 )
v1 = TriangleVertex( s, t, 1 )
v2 = TriangleVertex( s, t, 2 )
ax# = VertexX( s, v1 ) - VertexX( s, v0 )
ay# = VertexY( s, v1 ) - VertexY( s, v0 )
az# = VertexZ( s, v1 ) - VertexZ( s, v0 )
bx# = VertexX( s, v2 ) - VertexX( s, v1 )
by# = VertexY( s, v2 ) - VertexY( s, v1 )
bz# = VertexZ( s, v2 ) - VertexZ( s, v1 )
Nx# = ( ay * bz ) - ( az * by )
Ny# = ( az * bx ) - ( ax * bz )
Nz# = ( ax * by ) - ( ay * bx )
Ns# = Sqr( Nx * Nx + Ny*Ny + Nz*Nz )
Nx = Nx / Ns
Ny = Ny / Ns
Nz = Nz / Ns
For v = v0 To v2
VertexNormal s, v, Nx, Ny, Nz
Next
Next
Next
End Function