Scripting OBSE18 Coolness

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
Tools used in this tutorial

Required


OBSE Coolness[edit | edit source]

I am so jazzed about OBSE 18 that I wanted to create a page to share its coolness.

An array of functions[edit | edit source]

Now that OBSE v18 supports functions you can do some really cool things with it. You could probably do this before with regular functions on objects with OBSE. However functions do not have to be attached to anything.

First lets build some functions:

scn TestFunction1

begin Function {}
  PrintC "TestFunction1 called"
end

scn TestFunction2

begin Function {}
  PrintC "TestFunction2 called"
end

scn TestFunction3

begin Function {}
  PrintC "TestFunction3 called"
end

Obviously those would be independent scripts.


Now lets have some fun with them:

; This would be in some persistent location like a quest script.
array_var functList
...
; This would be in the gamemode part or something.
if(functList == 0)
  let functList := ar_Construct StringMap
  let functList["TestFunction1"] := TestFunction1
  let functList["TestFunction2"] := TestFunction2
  let functList["TestFunction3"] := TestFunction3
endif
...
; Now somewhere else you can call your functions from the array.
; Arguments work too.
ref functRef
let functRef := functList["TestFunction2"]
Call functRef

I am using this feature for my current mod. I use it to apply standardized effects of variable value to an object. I will be able to have my mod cycle through all effects of varying types and functions to operate on those types with a bunch of conditions to control execution. This allows for later mods to add functionality too!


Here is a way to cycle through without knowing the function names:

array_var functList
array_var item
ref functRef
foreach item <- functList
  let functRef := item["value"]
  Call functRef
endif


Some ideas for using this:

-Use it to build a stack of code to apply to a situation.
-Complex spell list?
-Complex AI commands?
-Record events in Quest then automagically run a set of commands based upon events?
-Ooh, I got it! Index a list of effects for a spell based upon the object name or ID. When the object is activated then cycle through list that is unique to that item. Extremely complex script spells made up of smaller functions. Could even be configured in game if someone were to get creative! No more limit of 8 effects on a magical item!
-The list of possibilities is endless.