Linked List Tutorial

Revision as of 22:03, 4 May 2006 by imported>Tegid (Added parent link)

Unfortunate Realities

Before we get started, let me address some unfortunate realities. The code I wrote earlier won't work. You can't call

  set Curr.Child to Something

On a non-persistent reference. That means I can't call it on any of the objects I create in game. So that causes a serious problem. Fortunately there is a way to address it.

We create a Persistent Reference that the Nodes can talk to and pass data through. I call the base object of this Persistent Reference the DSTDataMgr. So a very basic DSTDataMgrScript will look like this

scn DSTDataMgrScript
ref Head               ;This script will store the head of my list
ref ChildRef           ;This is somewhere to store the data we need to know as a  
                       ;child node
long Number_of_Nodes   ;It is helpful to know this information and it allows us to 
                       ;number the nodes

Now I know how to store the ChildRef that the Prev Node needs to store, but how do I tell the Prev Node that it needs to set it's Child Node? We add one more line to the DSTDataMgrScript

short setChild

Then we need to add an OnActivate block to the DSTDataMgrNode. This is an easy way to tell a node to do something. We will also need to define a new Persistent Reference DSTDataMgr. Do this by dragging a DSTDataMgr into a gameworld Cell (I like to put it by the exit to the Imperial Sewers (Tamriel->ICPrisonSewerExit01) but that's just personal taste). Then name it pDSTDataMgrRef and check the Persistent reference checkbox. Now we can access it in our DSTDataNodeScript

scn DSTDataNodeScript
ref Child
long Number

begin OnActivate
  if (pDSTDataMgrRef.setChild == 1)
    set Child to pDSTDataMgrRef.ChildRef
    set Number to pDSTDataMgrRef.Number_of_Nodes
    set pDSTDataMgrRef.Number_of_Nodes to pDSTDataMgrRef.Number_of_Nodes + 1
    set pDSTDataMgrRef.ChildRef to 0
    set pDSTDataMgrRef.setChild to 0
  endif
end

With these two scripts we can set up our list like so

scn DSTTestScript1
short count
ref NewNodeRef
ref Prev

begin GameMode
  if (count < 20)
    set count to count + 1
    set NewNodeRef to PlaceAtMe DSTDataNode 1, 0, 0
    if (Prev == 0)
      set pDSTDataMgrRef.Head to NewNodeRef
    else
      set pDSTDataMgrRef.ChildRef to NewNodeRef
      set pDSTDataMgrRef.setChild to 1
      Prev.Activate Prev 1
    endif
    set Prev to NewNodeRef
  endif
end

But there are a couple of problems. Unfortunately, they will have to wait for a week or so because I am out of time for today and leaving for awhile. This should give you plenty of questions.

Previous Page

Dynamic Storage