Reference from ReferenceAlias with fill type "Create...&

Post » Mon Nov 19, 2012 4:05 pm

Is 2AM here and I'm going insane...I hope I will make any sense...

I have a container and a book type defined in CK, each with own custom script.
Then I have a quest with two ReferenceAliases using "Fill type"-"Create reference to object": one trys to create a sayd container "At" Player, the other one a book "In" Player (inventory)
Now, from where I called start() for that quest I call getReference() on those aliases and try to cast them to the script I put on each to call a method of mine.
With what I described here the cast for the book returns None and checking with Debug.Notification(XXXAlias.getReference()) without a cast the book is displayed as "[ObjectReference" but the container is displayed as "[MYContainerScript"
But the strangest part is still to come: I go to the aliases tab supposing "In" is to blame and change it to "At" for the book. Now the book is printed as "[MyBookScript" BUT the container is "[ObjectReference" and can't be casted. And I didn't touch the container alias, nor the aliases order, nor the notifications, the only change I made was "In"->"At" just for the book alias.
Objects are definitly created, quest runs well, even text replacement on both of their names works. More than that when the book can't be casted (the "In" version) the onRead() notification from my custom script works if i click on it in the inventory.

Please people tell me if have you seen something like this. Please someone test it cause I'm leaving for the weekend and won't have the CK till Monday, but can access the forum. If I'm not insane now I'll be till then thinking of this if I get no answer here.
User avatar
Life long Observer
 
Posts: 3476
Joined: Fri Sep 08, 2006 7:07 pm

Post » Mon Nov 19, 2012 10:40 am

first and formost it would help the script wizards here if you posted your script so they can se if you missed something og placed a letter wrong ((do use the spoiler or code tag for this)

Just a friendly heads up :)

as for your problem I'm not that great a wizard when it comes to scripts or aliases, but from the sound of it (i might be wrong) it could be a property error
User avatar
sunny lovett
 
Posts: 3388
Joined: Thu Dec 07, 2006 4:59 am

Post » Mon Nov 19, 2012 6:39 am

Just a guess, but does your script perhaps extend http://www.creationkit.com/ReferenceAlias_Script? If that's the case, then you won't want to call http://www.creationkit.com/GetReference_-_ReferenceAlias on it. Instead, just cast it straight from a ReferenceAlias.

Cipscis
User avatar
Victor Oropeza
 
Posts: 3362
Joined: Sun Aug 12, 2007 4:23 pm

Post » Mon Nov 19, 2012 9:54 am

I didn't post the script as I deem it very simple, the rest of the setup with the references may be more complex.
I have a magic effect on a scroll that's supposed to create a book in player inv and a container at the current location. I have a quest for those items as I want do do some text replacement on their names, and trust me I grasp that since my named soul gems mod.
The book an the barrel have a script and from the magic effect after they are created I want to call some methods. So the effect script has some ReferenceAlias properties pointing at the quest.
Cipscis you say I need to cast ReferenceAlias directly to my book/container script? I doubt that, my scripts are extending ObjectReferences not the aliases, cause the quest is restarted and new aliases generated each time the script is used.
Simpliy alias.gerReference() sometimes is printed with Debug.Notification as their script name and sometime as ObjectReference
User avatar
Silencio
 
Posts: 3442
Joined: Sun Mar 18, 2007 11:30 pm

Post » Mon Nov 19, 2012 3:08 pm

I didn't post the script as I deem it very simple, the rest of the setup with the references may be more complex.
I have a magic effect on a scroll that's supposed to create a book in player inv and a container at the current location. I have a quest for those items as I want do do some text replacement on their names, and trust me I grasp that since my named soul gems mod.
It was in no way ment as you didnt know what you are doing or do not understand the scripting but it is hard for the rest of us to help you fully without the script/scripts that are giving you problems :)
User avatar
Marcin Tomkow
 
Posts: 3399
Joined: Sun Aug 05, 2007 12:31 pm

Post » Mon Nov 19, 2012 12:15 pm

Here's the code as it seems creating the objects via placeAtMe suffers from the same bug:
Scriptname LH_CreateEffectScript extends activemagiceffect Book property LH_Book AutoContainer property LH_Container AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)ObjectReference bookRef = akCaster.PlaceAtMe(LH_Book)ObjectReference containerRef = akCaster.PlaceAtMe(LH_Container, 1, true)Debug.Notification("Book ref "+bookRef)Debug.Notification("Container ref "+containerRef)Debug.Notification("Book casted "+bookRef as LH_BookScript)Debug.Notification("Container casted "+bookRef as LH_ContainerScript)endEvent
Then I wanted to add the book in player inventory and call some of my functions on my book/container scripts.
Sometimes it prints "Book/Container ref [ObjectReference" in which case the casting returns and prints None. Sometime it prints "Book ref [LH_BookScript" or "Container ref [LH_ContainerScript" in which case casting works and prints the same.
Just adding few more lines like adding the 3th and 4th notification to the script changed which was ok and which wasn't. Both happend to not be ok too.
You must admit this is a huge one...
User avatar
Laura-Jayne Lee
 
Posts: 3474
Joined: Sun Jul 02, 2006 4:35 pm

Post » Mon Nov 19, 2012 5:25 am

OK guys, I still claim there's an issue in CK.
Mod which I was working on is uploaded here: http://skyrim.nexusmods.com/mods/24879
The file marked as version BUGGED uses the reference created via aliases method as per OP, version 1.00 uses placeAtMe + a fix you can easily identify and remove if you wish to test my claims.
Waiting feedback on the mod itself and on this issue.
User avatar
CHANONE
 
Posts: 3377
Joined: Fri Mar 30, 2007 10:04 am

Post » Mon Nov 19, 2012 11:30 am

Then I wanted to add the book in player inventory and call some of my functions on my book/container scripts.

Er, you CANNOT call functions on an object when it is inside a container. Just sayin' :banana:

"Once an object has been added to a container it is no longer valid to call functions on it. Functions on self will fail to run with an error." - http://www.creationkit.com/OnContainerChanged_-_ObjectReference

I rest my case.

I have a magic effect on a scroll that's supposed to create a book in player inv

... in which case, if you try to cast the scroll as its script it will return None.


You must admit this is a huge one...

... but not by Bethesda, sorry :bunny: it's best not to write code at 2am when you are too tired to think straight.
User avatar
Danel
 
Posts: 3417
Joined: Tue Feb 27, 2007 8:35 pm

Post » Mon Nov 19, 2012 3:15 am

If I remember correctly, references created in an inventory, which have never existed outside of an inventory, are treated differently from other references. Try adding them to the relevant inventory by first creating them in the world via http://www.creationkit.com/PlaceAtMe_-_ObjectReference

Cipscis
User avatar
Ezekiel Macallister
 
Posts: 3493
Joined: Fri Jun 22, 2007 12:08 pm

Post » Mon Nov 19, 2012 4:24 pm

Also, try PlaceAtMe's abForcePersist for the BOOK. The created BOOK REFR should then retain its FormID whether in a container or not.

Try setting remote properties, like in a quest, to the new references?
User avatar
Stephanie Kemp
 
Posts: 3329
Joined: Sun Jun 25, 2006 12:39 am

Post » Mon Nov 19, 2012 3:51 pm

@threedee
Placing the book in the container (player) was on that piece of code I posted AFTER all those notifications and they still behaved as I say. Also the container failed to be casted.
@Cipscis
The attempt with PlaceAtMe is in the code fragment I posted, still had issues with it.
@JustinOther
Used abForcePersist for the container, it still happend to fail

In the end the "solution" I used that never failed yet is this:

int i = 0ObjectReference bookRefwhile (bookRef as LH_HIB_BookScript == None && i<5)  bookRef.disable()  bookRef.deleteWhenAble()  bookRef = akCaster.PlaceAtMe(LH_HIB_Book)  i+=1;endWhileif (bookRef as LH_HIB_BookScript == None)  bookRef.disable()  bookRef.deleteWhenAble()  Debug.Notification("Something went wrong with book creation")  returnendIfObjectReference containerRefwhile (containerRef as LH_HIB_ContainerScript == None &&  i<10)  containerRef.deleteWhenAble()  containerRef  = akCaster.PlaceAtMe(LH_HIB_Container, abInitiallyDisabled = true)endWhileif (containerRef as LH_HIB_ContainerScript == None)  containerRef.deleteWhenAble()  Debug.Notification("Something went wrong with container creation")  returnendIfLH_HIB_ManagementQuest.start()    InventoryBook.ForceRefTo(bookRef)    InventoryContainer.ForceRefTo(containerRef)        LH_HIB_BookScript invBook = (bookRef as LH_HIB_BookScript)        LH_HIB_Books.addForm(invBook)    LH_HIB_Locations.addForm(InventoryLocation.getLocation())    invBook.setLocation(InventoryLocation.getLocation())    LH_HIB_Containers.addForm(InventoryContainer.getReference())        invBook.setContainer(containerRef)        LH_HIB_ManagementQuest.setStage(10)        akCaster.AddItem(bookRef)    LH_HIB_ManagementQuest.stop()    InventoryBook.clear()    InventoryContainer.clear()

The created BOOK REFR should then retain its FormID whether in a container or not.
I wander if this is not related to the other problem I encountered: http://www.gamesas.com/topic/1413484-getformindex-ck-wiki-style-issue-form-not-found-when-in-the-list/page__fromsearch__1
Equality of form Id worked, but not of references. The code can be still found commented in the mod.
User avatar
IsAiah AkA figgy
 
Posts: 3398
Joined: Tue Oct 09, 2007 7:43 am


Return to V - Skyrim