Jump to content

(myActor.placeAtMe(MyCustomObject) as MyCustomObjectScript) is None


LukeH

Recommended Posts

I initially posted this http://forums.bethsoft.com/topic/1413703-reference-from-referencealias-with-fill-type-create-cant-be-casted-to-the-type-i-know-it-is/ but then I managed to pinpoint the problem so I add it here.

I have created a book and a container in CK with scripts attached to them then. I create references of those types, from a magic effect in my case, and I want to cast them as their attached script and to call my functions on them. This simply seem to work sometime and sometime it won't work.

 

Scriptname LH_CreateEffectScript extends activemagiceffect
Book property LH_Book Auto
Container property LH_Container Auto
Event 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.

Am I doing something wrong? Have unrealistic expectation?

I believe this is a nasty bug as it sometimes simply work and sometime won't.

Edited by LukeH
Link to comment
Share on other sites

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 bethsoft forum 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.

Link to comment
Share on other sites

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

 

From the CK wiki: "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." :whistling:

Edited by steve40
Link to comment
Share on other sites

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.

Try adding "Utility.Wait(2)" after the placeatme and before printing the debug messages. You need to allow sufficient time for the game to place the objects and for said objects to initialize, load their 3D and run their spells/magic effects.

 

EDIT: tip: you should also be keeping an eye on your papyrus logs for run-time errors.

Edited by steve40
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...