bug in my code and i don't see why... (short code)
Blitz3D Forums/Blitz3D Beginners Area/bug in my code and i don't see why... (short code)
| ||
Hello Blitzers, I have a bug in my code and i don't see why, so maybe your eyes and mind can help me to see what's the problem... I have removed the more code that i was able to so that you can quickly see what is the problem : Graphics3D(800,600,32,2) SeedRnd(MilliSecs()) Origine = CreateCube() ScaleMesh(Origine,0.01/2,0.01/2,0.01/2) EntityColor(Origine,255,000,255) PositionEntity(Origine,0,0,0,True) Global Camera = CreateCamera() CameraRange(Camera,0.1,100) CameraClsColor(Camera,000,000,000) Global BuildingsCount% Dim BuildingRoot(100) Dim BuildingXZRadius#(100) Dim BuildingPickable(100) Dim BuildingRenderer(100) BuildBuildings() Global OLight = CreateLight(2) LightRange(OLight,3.0) LightColor(OLight,Rand(025,255),Rand(025,255),Rand(025,255)) PositionEntity(OLight,1.5,0.5,1.5,True) ;HideEntity(OLight) AmbientLight(060,060,060) ;DayAmbient ;AmbientLight(030,030,030) ;NightAmbient Global LoopTimer = CreateTimer(20) Global MainLoopMsTime% Main() ClearWorld() End() Function Main() While( KeyDown(1)<>1 ) MainLoopMsStart% = MilliSecs() ;some code was here... If( KeyDown(2)=1 ) Wireframe(True) Else Wireframe(False) EndIf SetBuffer(BackBuffer()) RenderWorld() SetFont(Arial14Font) Color(255,000,255) Text(0,0,"Tris = "+TrisRendered()) WaitTimer(LoopTimer) VWait() Flip() MainLoopMsTime% = MilliSecs() - MainLoopMsStart Wend End Function Function BuildBuildings() ;For i% = 1 To 1 Step 1 BuildingsCount = BuildingsCount + 1 Id% = BuildingsCount BWidth# = Rand(6,12) BHeight# = 3 BDepth# = Rand(6,12) LevelsCount% = 6;Rand(1,10) ;some code was here... PositionEntity(OLight,0,(Rand(0,LevelsCount-1)*3)+1.5,0,True) ;this provokes an error ;PositionEntity(OLight,0,0,0,True) ;this also provokes an error... ;Next End Function I get a RunTimeError "Entity does not exist" but the variable which stores the reference of the "OLight" is global... Any suggestions is appreciated. Thanks, |
| ||
BuildBuildings() is called before OLight is created. |
| ||
Beginner mistake ! Aaah ! Thanks for your eyes and mind. I have not seen it after several rereads ! Testing... Yes it was that. Thanks again. :) |
| ||
Meh, I make mistakes like this all the time and I do this stuff for a living. Wood for the trees and all that. |