Jump to content

Ref-Walking and Cell loading


sagittarius22

Recommended Posts

So I'm making some ref-walking in my script but I heard that to avoid crashes I had to make sure that the cell was loaded, or something like that: crash may avoid when changing cell.

 

My question: is this script correct?

 

scn SAGApplyScriptQUESTSCRIPT

ref rRef
ref rcurrentcell
ref rlastcell


begin GameMode

         set rCurrentCell to player.getparentcell
	set rref to GetFirstRef 200 0 0

	Label 1

set rLastCell to player.getparentCell
  if rCurrentCell == rLastCell	
    	if ( rref )

         rRef.CIOS SAGApplyScriptActorEffect
	set rref  to apple
         set rRef to GetNextRef
	
		Goto 1
       endif
   elseif rCurrentCell != rLastCell

         set rCurrentCell to player.getparentcell
         set rLastCell to player.getparentcell

   endif
end

Edited by sagittarius22
Link to comment
Share on other sites

All scripts run in a single thread. So no 2 scripts will ever run at the same time.

Each script will always complete within a single frame. The next frame is not rendered until scripts complete.

 

So basically within your refwalk loop, all the refs will be valid. If they weren't loaded then there'd be nothing to 'walk'.

If you refwalk an unloaded cell you'll only get persistent refs in your loop.

 

So unless you want to simulate an OnCellChange event, you needn't worry about the getparentcell (gpc).

 

ref rRef
ref rLastCell

begin GameMode
 if player.gpc != rLastCell ;Simulate OnCellChange

   set rref to GetFirstRef 200 0 0
   Label 1

   if ( rref )
     rRef.CIOS SAGApplyScriptActorEffect
     set rref  to apple
     set rRef to GetNextRef
     Goto 1
   endif

   set rLastCell to player.gpc; Cache last processed cell
 endif
end

 

 

Edit: If the 'whole' gamemode block can be skipped when there's no cell change, then this would be more efficient.

begin GameMode
 if player.gpc == rLastCell
   return
 endif
 set rLastCell to player.gpc

 ;Stuff to do OnCellChange

end

Edited by tunaisafish
Link to comment
Share on other sites

Ok okay, maybe I was not clear enough :)

WHat I wanted is to avoid making refwalk while the cell is not loaded, to avoid crashes; as I understood, refwalking could make crashes occur when in a non-loaded cell...

Link to comment
Share on other sites

A refwalk that uses GetFirstRef/GetNextRef only operates on the current cell that the player is loaded in. I haven't had any, or heard of, crashing issues with changing cells with it. Though if your cell depth is too deep for exterior cells, depending on what you are doing with the refs, you may be causing more overhead than you need to, which over time can lead to a crash when transitioning exterior cell boundaries. Also, most of the time it doesn't make sense to ref walk every frame, so using a quest script with a second or two delay helps with performance too.

 

In your script, in exterior cells, you will be applying the actor effect to every actor in the player's current cell (0 depth). If the player is right near a cell boundary, there could be another actor right there in an adjacent cell that won't be scanned. So perhaps you would want to use a cell depth of 1, for the current cell and 8 adjacent cells, then limit your actor effect to a distance from the player to the Reference.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...