One of the most common tasks in a script is looping over rays; whether it be to change some ray attribute or find specific rays. As a result of FRED's buffer interlacing, a particular method is recommended when looping over rays. The commands GetFirstRay, GetNextRay (GetLastRay and GetPreviousRay) were added in FRED version 7.0 to skip over empty slots in the ray buffer caused by ray splitting in the multi-threaded raytrace algorithm.
Dim tr As T_RAY success=GetFirstRay(i,tr) While success : 'do something with the ray data : success=GetNextRay(i,tr) Wend
Alternatively, the standard For..Next loop can be edited to accomplish the same purpose. Simply adding the IsRayActive or IsRayLive command forces FRED to skip over empty slots in the ray buffer. We recommend using IsRayActive when some of the rays may have had their active state set to False for some other reason (ray filtering):
Dim tr As T_RAY For i=0 To GetRayCount() -1 If IsRayActive(i) Then GetRay i, tr : 'do something with the ray data : End If Next i
|