How can I fill a property with a script?

Post » Fri Aug 23, 2013 11:12 am

So I was reading one of the forum threads when I noticed that one of the users (docblacky) posted the following code:

Spoiler


What I understood from this is that you are allowed to use functions from another script IF you declare that script as a property. I thought, "wow, this is pretty handy." So I decided to set up my own example:

Spoiler

Scriptname TestPatrolScript extends ObjectReference  {Creates actors that patrol routes}objectReference property spawnMarker autoobjectReference property gotoMarker autoactorBase property patrolSoldierBase autoTestFunctionScript property funcScript autoevent onEquipped(actor akActor)    if akActor == game.getPlayer()        actor patrolSoldier =  (spawnMarker.placeAtMe(patrolSoldierBase, 1, true)) as actor        utility.wait(2)        TestFunctionScript.patrolFunc(patrolSoldier, gotoMarker)    endIfendEventScriptname TestFunctionScript extends Actor  {Testing sharing functions between scripts}actor function patrolFunc(actor soldier, objectReference endMarker)    soldier.pathToReference(endMarker, 0.5)endFunction

The problem is that I don't actually know how to fill the property "funcScript" with "TestFunctionScript". I mean once I declare the property, and then I go to the properties tab of the script and click the "edit value" button, I then get the option to "pick reference in render window" which doesn't help because I can't pick a script in the reference window. So some clarification would be much appreciated.

Also before people mention it, I do realize that this example can also be done by casting "patrolSoldier" to type TestFunctionScript (i.e. ptrolSoldier as TestFunctionScript) and I also do realize that the import command can also be used to achieve what I'm trying to do. This is just an example for the sake of testing the property method.

User avatar
Andrew
 
Posts: 3521
Joined: Tue May 08, 2007 1:44 am

Post » Fri Aug 23, 2013 10:40 am

Because TestFunctionScript is extending an Actor, a specific reference in the world with the script attached has to be selected.

To make the TestFunctionScript script "global", it can be set to extend the Quest base script and attached to a helper quest. The funcScript property can then be initialized correctly by selecting the helper quest with the script.

User avatar
Sherry Speakman
 
Posts: 3487
Joined: Fri Oct 20, 2006 1:00 pm


Return to V - Skyrim