Accessing a reference from a function

Post » Thu Sep 10, 2015 12:40 pm

I'm wanting to split up a script into functions for easier management and performance reasons. I have a script attached to a torch. The torch is not a persistent reference, it becomes a reference through dropping or the use of PlaceAtMe (which I clean up the reference after it is generated). There ios some math that runs each frame, and I'd like to put that off into a function so that it only gets called when needed. Good for performance (which will be negligable, I know, but it will be done), and good for tidiness. I'm wondering what is the best way to access the torch reference in the function script, which will be called from the torch object script. You need a quest or persistent reference to access a reference from another script, but is there another way? I've tried the ol' "MoveTo" technique of setting the torch form into a dummy cell and moving it from that cell. But it didn't work too well. Because of the nature of the mod, the multiple torches can be in the game world at any one time. So the references get mixed (I think).

So, how can I access a reference from an object script attched to a torch? The reference is the torch itself.

User avatar
Chavala
 
Posts: 3355
Joined: Sun Jun 25, 2006 5:28 am

Post » Thu Sep 10, 2015 1:42 pm

You may not need to,

A Function runs on the calling reference. For example, this function:

scn MyMoveFunctionbegin Function {}    moveto AnvilFocsleMarkerend

If called on the Player ( playerref.call MyMoveFunction ) will move the Player to Anvil, If called on your torch ( YourTorch.call MyMoveFunction ), will move your torch.

Since your function will be called from the torch script, it will `inherit` the torch as the target reference and any unreferenced (?) command (like the MoveTo in the example) will be applied to the torch.

User avatar
ruCkii
 
Posts: 3360
Joined: Mon Mar 26, 2007 9:08 pm

Post » Thu Sep 10, 2015 11:19 am

Excellent to hear that, QQuix. Thanks. I guess I also could pass the reference like this (attached to the torch):

Let Self := GetSelfCall MyFunction Self
User avatar
Jeremy Kenney
 
Posts: 3293
Joined: Sun Aug 05, 2007 5:36 pm

Post » Thu Sep 10, 2015 1:12 am

For the second syntax, you need to define the torch as a parameter to your function.

User avatar
stevie trent
 
Posts: 3460
Joined: Thu Oct 11, 2007 3:33 pm


Return to IV - Oblivion