How to pass ObjectReference from one script to another.

Post » Tue Jun 19, 2012 2:47 am

I faced another problem with my scripts. I'm trying to create spell with will teleport player to small house and take him back to place where he was casting spell, after activating door. One script is responsible for teleporting player and placing marker on player position. It also should pass ObjectReference (marker) to script. I've got problem with passing reference. Responding to wiki everything should work, but it does not.

Here is a code:
Scriptname TOWBook extends ActiveMagicEffectObjectReference Property BookTarget autoTOWDoorBack Property Target auto        ;Door with attached TOWDoorBack Script are target of this property (chosen in CK)ObjectReference ResultEvent OnEffectStart(Actor Caster, Actor SpellTarget)Debug.Notification("Started GetFormID: " + Result.GetFormID())if(Game.GetPlayer().GetParentCell() != BookTarget.GetParentCell())  Result = Game.GetPlayer().PlaceAtMe(Game.GetForm(0x0000003B), 1, true)  Debug.Notification("Temp: " + Result.GetFormID())  Utility.Wait(5)  Target.Target = Result  if (Result.GetFormID() != 0)   Game.GetPlayer().MoveTo(BookTarget)  else   Debug.Notification("Error! Cast again!")  endif else  Debug.Notification("You already at home!")endIfDebug.Notification("Finished GetFormID: " + Result.GetFormID() + " " + Target.Target.GetFormID())EndEvent

Teleporting is working and result of Result.GetFormID() is number (so game created object) but Target.Target.GetFormID() is = 0 - so the reference wasn't passed.


Scriptname TOWDoorBack extends ObjectReference ObjectReference Property Target autoEvent OnActivate(ObjectReference akRef)Debug.Notification("Door GetFormID: " + Target.GetFormID())Game.GetPlayer().MoveTo(Target)if(Game.GetPlayer().GetParentCell() == Target.GetParentCell())  Target.Delete()  endIfEndEvent

This script is attached to door. Result of Target.GetFormID() is 0.

Any ideas?
User avatar
Annika Marziniak
 
Posts: 3416
Joined: Wed Apr 18, 2007 6:22 am

Post » Tue Jun 19, 2012 4:09 am

How are you filling the Target and BookTarget properties?

Do you have them filled from the properties window, or are you assigning values in some part of the script we haven't seen?
User avatar
Sara Johanna Scenariste
 
Posts: 3381
Joined: Tue Mar 13, 2007 8:24 pm

Post » Tue Jun 19, 2012 12:37 am

From properties window. BookTarget is COCMarker in target cell (and it is working, because I am teleported inside that cell) and Target is door with TOWDoorBack script attached in target cell.
User avatar
Marie
 
Posts: 3405
Joined: Thu Jun 29, 2006 12:05 am

Post » Tue Jun 19, 2012 6:52 am

I can't think of any reason why you would legitimately want to use http://www.creationkit.com/GetForm_-_Game. You should be using a property for this.

I'm not sure what the problem is in your script. At a guess, perhaps the cell you're testing is being reset between setting the value of your property and moving to the cell, so the property's value is being reset to None?

Cipscis
User avatar
Robert DeLarosa
 
Posts: 3415
Joined: Tue Sep 04, 2007 3:43 pm

Post » Tue Jun 19, 2012 10:53 am

I can't think of any reason why you would legitimately want to use http://www.creationkit.com/GetForm_-_Game. You should be using a property for this.

I'm not sure what the problem is in your script. At a guess, perhaps the cell you're testing is being reset between setting the value of your property and moving to the cell, so the property's value is being reset to None?

Cipscis

I use Game.GetForm() because I want to create new, "pure", object (like using "new" in programming).

I don't know how, but it started working as it is :blink: So problem solved...
User avatar
Jessica Nash
 
Posts: 3424
Joined: Tue Dec 19, 2006 10:18 pm

Post » Tue Jun 19, 2012 2:21 am

It works as-is, but it's an incredibly messy way to do things. Scripts should be ignorant as to the contents of data files, and that function violates that principle.

http://www.creationkit.com/PlaceAtMe_-_ObjectReference works perfectly well without http://www.creationkit.com/GetForm_-_Game.

Cipscis
User avatar
Juan Cerda
 
Posts: 3426
Joined: Thu Jul 12, 2007 8:49 pm


Return to V - Skyrim