Difference between revisions of "Scripting Tutorial: Working with FormLists"
Scripting Tutorial: Working with FormLists (edit)
Revision as of 11:22, 3 August 2009
, 11:22, 3 August 2009finished tutorial
imported>Omzy m |
imported>Omzy (finished tutorial) |
||
Line 1: | Line 1: | ||
==IMPORTANT== | ==IMPORTANT== | ||
'''You will need [[Fallout Script Extender|Fallout Script Extender (FOSE)]] for this tutorial.''' | '''You will need [[Fallout Script Extender|Fallout Script Extender (FOSE)]] for this tutorial.''' | ||
Line 81: | Line 78: | ||
*You can use the [[ListGetCount]] function. | *You can use the [[ListGetCount]] function. | ||
=Using Lists to Create Floating Text= | |||
This example goes beyond what a casual modder might attempt to accomplish, but it displays the abilities of lists quite well. | This example goes beyond what a casual modder might attempt to accomplish, but it displays the abilities of lists quite well. | ||
Line 165: | Line 162: | ||
End | End | ||
The script was cut short because it is a bit tedious, since we have 9 names to print. The script could also quickly get long if we put more instructions into each loop. | |||
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: | 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: | ||
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 | |||
;PRINT NAMES | |||
Label 1 | |||
set letterList to ListGetNthForm namesList countNames | |||
set countLetters to 0 | |||
Label 2 | |||
set currentLetter to ListGetNthForm letterList countLetters | |||
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 countLetters to countLetters + 1 | |||
if countLetters < ListGetCount letterList | |||
GoTo 2 | |||
endif | |||
set countNames to countNames + 1 | |||
;set position of next name's first letter | |||
set letterPosX to firstLetterPosX + nameOffsetX * countNames | |||
set letterPosY to firstLetterPosY + nameOffsetY * countNames | |||
set letterPosZ to firstLetterPosZ + nameOffsetZ * countNames | |||
if countNames < ListGetCount namesList | |||
GoTo 1 | |||
endif | |||
End | |||
That was the entire script to print all 9 names in a cell. If these initial positions are changed, this script can print these names anywhere in the game world. If we add more names or want to change the names, this can easily be done in the editor without modifying the script. | |||
The moral of the story is: '''there is a lot you can accomplish by working with FormLists'''. |