CountLines ( line_list )
Parameters
| line_list - a line-list entity created with CreateLineList |
Description
|
Returns the number of segments currently stored in a line list. CountLines tells you how full the list is. Valid indexes for SetLine run from 0 through CountLines(line_list)-1, so it is the natural loop bound when you update every segment, and the natural guard before adding more: each list caps out at 65,536 segments, and AddLine stops the program with a runtime error beyond that. A trail that grows every frame can use CountLines to decide when to trim itself with ClearLines. Passing an entity that is not a line list stops the program with a runtime error. Requires Extended mode. See also: AddLine, SetLine, ClearLines, CreateLineList. |
Example
; CountLines Example ; ------------------ ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() SeedRnd MilliSecs() camera=CreateCamera() PositionEntity camera,0,1,-9 ; A starfield sketch that grows one random line per frame scribble=CreateLineList() EntityColor scribble,160,120,255 LineWidth scribble,2 While Not KeyDown(1) ; Space adds a burst of ten extra segments If KeyHit(57) Then For n=1 To 10 AddLine scribble,Rnd(-3,3),Rnd(-2,2),0,Rnd(-3,3),Rnd(-2,2),0 Next EndIf ; One new segment every frame keeps the sketch growing AddLine scribble,Rnd(-3,3),Rnd(-2,2),0,Rnd(-3,3),Rnd(-2,2),0 ; CountLines drives the game logic: wipe the sketch once it reaches 200 segments If CountLines(scribble)>=200 Then ClearLines scribble ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Arrow keys: move camera Space: add 10 segments Esc: exit" Text 0,20,"CountLines(scribble) = "+CountLines(scribble)+" (auto-clears at 200)" Flip Wend End
Index