Script Comparison Tests

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Here's a list of comparisons of functionally equivalent scripts.

If you would like to contribute, post the scripts that you're comparing. Make sure the scripts are functionally equivalent, at least they can be interchanged in most cases. Also, note that the scripts don't have to actually do anything themselves, but can be parts of other scripts (but only test these particular snippets).

'If' vs. 'Set'[edit | edit source]

If you need to make sure a variable is set to a certain number every time the script runs, is it faster to set the number or use an if test to make sure it's the same. A good example would be setting the fQuestDelayTime for a quest. Here's the two scripts:

scn aaaTestScript

float fQuestDelayTime

begin GameMode
  if (fQuestDelayTime != .01)
    set fQuestDelayTime to .01
  endif
end

and

scn aaaTestScript

float fQuestDelayTime

begin GameMode
  set fQuestDelayTime to .01
end

Results: Mixed bag - This

begin GameMode
  if fQuestDelayTime
    set fQuestDelayTime to .01
  endif
end

is faster than

begin GameMode
    set fQuestDelayTime to .01
end

but this

begin GameMode
  if (fQuestDelayTime == 0)
    set fQuestDelayTime to .01
  endif
end

is slower. So, if your 'if' test doesn't have any operators it's faster to test first, otherwise just set the variable.

GetParentCell vs. GetInSameCell[edit | edit source]

To check whether an object is in the same cell as another, you could use

if (Object1.GetInSameCell Object2)

or

if (Object1.GetParentCell == Object2.GetParentCell)

It's faster to use GetInSameCell.

Also, GetParentCell seems to cause the same FPS drop whether you use it once or twice, so

if (Object1.GetParentCell == SomeCell)

is also slower than GetInSameCell. However, this might also mean that 2 GetParentCell functions might be faster than 2 GetInSameCell functions.