Pass reference to container to another script?

Post » Fri Nov 16, 2012 4:27 pm

I have a magic effect script that creates two items: a Container instance, and an Activator object. When the Activator is clicked on, I'd like it to open the Container. The player can cast the spell multiple times, creating multiple containers and activators, with each specific activator opening a specific container.

Opening is easy... but how do I make the Activator 's script KNOW about the Container? I assume there's some way to pass reference between objects, but I dont know how this works.

I want to do something like this Pseudocode:

(Effect Script)
ObjectReference magicLever = player.PlaceAtMe( MagicLeverActivator);
ObjectReference invisibleChest = player.PlaceAtMe( SecretContainer );
magicLever.chest = invisibleChest;


(then in the MagicLeverScript's onActivate:)
Self.chest.activate();


Optionally, I'd go for plan B: Have the Magic Lever create its own chest when the lever is created, but I can't find a suitable event to attach this to... there doesn't appear to be any kind of event for "I just got created" that I can see...



UPDATE: I think what I'm asking for is a LinkedRef, and I can see from this site http://www.cipscis.com/skyrim/tutorials/externalaccess.aspx how to ACCESS the linked ref, but I can't figure out how to SET it in the first place...



Suggestions?
User avatar
jason worrell
 
Posts: 3345
Joined: Sat May 19, 2007 12:26 am

Post » Fri Nov 16, 2012 7:05 pm

Have a look in the warehouse cells, for a normal "door and lever" setup.

I think there's a parent/child relationship that controls them.

If you can script that relationship (I assume you can, but I have never tried) then that should do the trick?
User avatar
marina
 
Posts: 3401
Joined: Tue Mar 13, 2007 10:02 pm

Post » Sat Nov 17, 2012 3:48 am

The problem is that these are "real" objects already set up in the CK - that's pretty easy.

I'm trying to figure out how to get two objects created via script to talk to each other. You're dead-on: I'm trying to script the relationship, because the objects in question do not actually exist until the player "summons" them.
User avatar
Dylan Markese
 
Posts: 3513
Joined: Sat Dec 01, 2007 11:58 am

Post » Fri Nov 16, 2012 11:04 pm

I'm almost certain you can do it via script ...

... Justin, or some other code god will know - Just keep this bumped (subtley :wink:)


Edit
Oh dear ...

http://www.creationkit.com/GetLinkedRef_-_ObjectReference
Get the parent object, no bother at all ...

SetLinkedRef ... No where to be found :(



There is probably a way to do it with Aliases and scripting ... I think that is what you are trying to do?

If you create a function that opens a container, that requires a ReferenceAlias to be passed to the function ... That ReferenceAlias being the ReferenceAlias you created/filled when the lever-and-chest-pair were created ... you should be able to pop open the right chest when the right lever is pulled.

(You might need a maximum number of spawned chest-lever-combos ... Or you might be able to create endless ReferenceAliases, via script, and so have unlimited?)

It's got to be doable ... Unless it is one of those things that looks doable, but turns out not to be (there's a big list of them ;))


Still needs Justin ...
User avatar
Eve Booker
 
Posts: 3300
Joined: Thu Jul 20, 2006 7:53 pm

Post » Fri Nov 16, 2012 8:32 pm

Actually all I'd really need, now that I think about it, is a way to know when the lever has been created... then IT can create its own ref to a container.... is there an event that I can use? cellattach doesnt sound right, and onInit seems to only work on scripts... any suggestions?
User avatar
Mistress trades Melissa
 
Posts: 3464
Joined: Mon Jun 19, 2006 9:28 pm

Post » Sat Nov 17, 2012 5:15 am

Well, it's not an answer, but I figured out a workaround... I simply create the chest inside the activator when the onActivate fires... there's no need for it beforehand. Works like a charm. Thanks for expending the braincell energy on my behalf tho =)
User avatar
Soraya Davy
 
Posts: 3377
Joined: Sat Aug 05, 2006 10:53 pm

Post » Fri Nov 16, 2012 8:59 pm

using placeatme for each magic cast will pollute your save game very quickly. it is better to create your lever and container in the CK and place them in an empty cell somewhere.


magic effect script:

ObjectReference Property MagicLever  Auto; --------MagicLever.MoveTo(Player)MagicLever.GetLinkedRef().MoveTo(Player)

Fill the objref property MagicLever with the placed lever in your empty cell. make sure the chest is link-ref'd to the lever and vice versa


on lever script:

GetLinkedRef().Activate(Player)
User avatar
Emma Louise Adams
 
Posts: 3527
Joined: Wed Jun 28, 2006 4:15 pm

Post » Fri Nov 16, 2012 3:12 pm

As I said, there can be any number of lever/chests. The method I described above is working well however. And to avoid clutter in the savefiles the object are properly destroyed when done.
User avatar
Matt Bee
 
Posts: 3441
Joined: Tue Jul 10, 2007 5:32 am

Post » Sat Nov 17, 2012 2:46 am

either way, calling placeatme on an activate block is not a good idea (regardless if it works, you will end up needing more damage control than its worth)

alternatively if you still want to refer to the created container directly across multiple scripts, in your effect script you can call:

(MagicLever as WhateverNameOfMagicLeversScript).InvisibleContainer = Player.PlaceAtMe(WhateverContainerBaseObject)


your magic lever's script would then need a objectreference property called InvisibleContainer initially set to a value of none (just declare it and leave it unfilled)

and call InvisibleContainer.Activate(Player) on the activate block
User avatar
Sammykins
 
Posts: 3330
Joined: Fri Jun 23, 2006 10:48 am

Post » Fri Nov 16, 2012 2:03 pm

Yay! That works perfectly.

Although as a programmer I really don't want to get into a discussion of the counterintuitivity of typecasting an object as its own child... but in a CK way it kinda makes sense. Ugh!
User avatar
Lily Evans
 
Posts: 3401
Joined: Thu Aug 31, 2006 11:10 am


Return to V - Skyrim