cannot use functions

Blitz3D Forums/Blitz3D Beginners Area/cannot use functions

sec05(Posted 2005) [#1]
hi there, want to ask something here.

i have been playing with blitz3d and I came across the using function. The problem is I have difficulty using it.

below is my code:

Graphics3D 800, 600

SetBuffer BackBuffer()

camera = CreateCamera()

CameraViewport camera, 0, 0, 800, 600

cube = CreateCube()

light = CreateLight()

PositionEntity cube, 0, 0, 5

While Not KeyHit(1)

turncube()

UpdateWorld

RenderWorld

Flip

Wend

Function turncube()
EntityAlpha cube, 0
End Function

End


Well, I got a "entity does not exists" error when i enable debug or i got a "memory access violation" when debug is off. anyone knows why?

thanks alot!


DH(Posted 2005) [#2]
Because Cube isn't a global Variable.

Above Graphics3d 800,600 you should have:
Global Cube=0

Then when your run this, you will not get "entity Does Not Exist".

Once you go into a Function, regardless of where the program control came from, that function can only access global variables to the program and local variables defined in that function. If you do not specify what type of variable it is (global or local) it will assume local.

Hope that helps.


sec05(Posted 2005) [#3]
thanks alot! it solved my problems!


_PJ_(Posted 2005) [#4]
I would recommend specifying that the function does something to an entity and that you should refer to that entity when the function is called... like this:


Graphics3D 800, 600

SetBuffer BackBuffer()

camera = CreateCamera()

CameraViewport camera, 0, 0, 800, 600

cube = CreateCube()

light = CreateLight()

PositionEntity cube, 0, 0, 5

While Not KeyHit(1)

If KeyDown(57)
turncube(cube)
End If

UpdateWorld

RenderWorld

Flip

EntityAlpha cube,1

Wend

Function turncube(entity)
EntityAlpha entity, 0
End Function

End



Rook Zimbabwe(Posted 2005) [#5]
I would also read about the forum codes so I can post code.
-RZ