Difference between revisions of "Scripting Tutorial: Working with FormLists"

Jump to navigation Jump to search
no edit summary
imported>Omzy
imported>Omzy
Line 92: Line 92:
*Our names are (courtesy of FF7):
*Our names are (courtesy of FF7):
#Cloud
#Cloud
#Barret
#Tifa
#Tifa
#Barret
#Aeris
#Aeris
#Red XIII
#Red XIII
Line 101: Line 101:
#Cid
#Cid


Let us create a [[FormList]] for each name that contains the letters of that name. If we try dragging and dropping ''B, a, r, r, e, t'' into a FormList for the name Barret, we will not be able to add the second ''t'' because dragging and dropping allows us only to add base forms to a FormList once, since they have the same FormID. So, we must add the letters as references via a script using [[ListAddReference]] OR by placing the letters into the world in a cell somewhere and dragging their references from the Cell View window.
Let us create a [[FormList]] for each name that contains the letters of that name. The name of each list will be ''nameX'' where ''X'' is the name (e.g. ''nameCloud''). If we try dragging and dropping ''B, a, r, r, e, t'' into a FormList for the name Barret, we will not be able to add the second ''t'' because dragging and dropping allows us only to add base forms to a FormList once, since they have the same FormID. So, we must add the letters as references via a script using [[ListAddReference]] OR by placing the letters into the world in a cell somewhere and dragging their references from the Cell View window. For this example, lets assume we've added them to a test cell somewhere so we can use [[MoveTo]] to relocate them to their destinations. We will add the letters so that the first letter of each name is at index 0.


If we wish to print these names into the world somewhere, we can use the [[Label]]/[[GoTo]] loop, one loop for each FormList of letters:
If we wish to print these names into the world somewhere, we can use the [[Label]]/[[GoTo]] loop, one loop for each FormList of letters:
  scn floatingNamesScript
  ;vars (not listed for brevity)
  Begin GameMode
    ;set first letter's position
    set firstLetterPosX to 1000
    set firstLetterPosY to 1000
    set firstLetterPosZ to 1000
    ;initialize current letter's position
    set letterPosX to firstLetterPosX
    set letterPosY to firstLetterPosY
    set letterPosZ to firstLetterPosZ
    ;distance to the next letter
    set letterOffsetX to 0
    set letterOffsetY to 5
    set letterOffsetZ to 0
    ;distance to the next name
    set nameOffsetX to 0
    set nameOffsetY to 0
    set nameOffsetZ to 10   
    set letterList to nameCloud
    Label 1
      set currentLetter to ListGetNthForm letterList count1
      currentLetter.MoveTo Player
      currentLetter.SetPos X letterPosX
      currentLetter.SetPos Y letterPosY
      currentLetter.SetPos Z letterPosZ
      ;add offsets for next letter
      set letterPosX to letterPosX + letterOffsetX
      set letterPosY to letterPosY + letterOffsetY
      set letterPosZ to letterPosZ + letterOffsetZ
      set count1 to count1 + 1
    if count1 < ListGetCount letterList
      GoTo 1
    endif
    ;set position of next name's first letter
    set letterPosX to firstLetterPosX
    set letterPosY to firstLetterPosY
    set letterPosZ to firstLetterPosZ
    set letterPosX to letterPosX + nameOffsetX
    set letterPosY to letterPosY + nameOffsetY
    set letterPosZ to letterPosZ + nameOffsetZ
    set letterList to nameBarret
    Label 2
      set currentLetter to ListGetNthForm letterList count2
      currentLetter.MoveTo Player
      currentLetter.SetPos X letterPosX
      currentLetter.SetPos Y letterPosY
      currentLetter.SetPos Z letterPosZ
      ;add offsets for next letter
      set letterPosX to letterPosX + letterOffsetX
      set letterPosY to letterPosY + letterOffsetY
      set letterPosZ to letterPosZ + letterOffsetZ


      set count2 to count2 + 1
    if count2 < ListGetCount letterList
      GoTo 2
    endif




As it would seem, a FormList is also an object in the editor, which has its own FormID. That makes a FormList a Form. What this means is that FormLists can contain other FormLists. This may seem a bit confusing if you've never learned any mid-level programming before, so lets look at the following script and see what it does:
    (etc)
  End


(script here)
This seems a bit tedious, since we have 9 names to print. The script could quickly get long if we put more instructions into each loop.


(add more scripting tricks/uses)
As it would seem, a FormList is also an object in the editor, which has its own FormID. That makes a FormList a Form. What this means is that FormLists can contain other FormLists. Lets use this to our advantage by making another FormList named ''namesList''. Now we will drag and drop all 9 of our name FormLists into this new FormList. Our script just got a whole lot shorter:
Anonymous user

Navigation menu