ecartsiger Posted March 16, 2013 Share Posted March 16, 2013 (edited) Hi, lets just dive in: Following http://www.cipscis.com/skyrim/tutorials/externalaccess.aspx I'm trying to extend Armor object, by adding functions GetID, SetID and variable myId.I also assigned Actor script to the player Actor form. In this script when player equips armor there should be assigned some id to equipped armor and then this id should be displayed using Debug.Notification(id).Problem is, that when I equip some armor in game it seems to me that GetID doesn't return expected myId value.I even added Debug.Notification("someString") to GetID and SetID but these notifications were never displayed. - What can be wrong with this approach?- Do I have to attach Actor script to Player Actor?I would like to handle OnObjectEquipped or similar event for all equipable armors in game, is there other approach? this script isn't attached to anything: Scriptname TestArmorChild extends Armor string myId Function SetID(string newId) myId = newId EndFunction string Function GetID () return myId EndFunction this script is attached to player reference alias Scriptname TestActorEquip extends ReferenceAlias Armor testArmor TestArmorChild armorChild Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) testArmor = akBaseObject as Armor if testArmor Debug.Notification("Armor equipped") armorChild = testArmor as TestArmorChild string id = "TEST" armorChild.SetID(id) if armorChild.GetID() == id Debug.Notification(id) endif endIf endEvent Edited March 17, 2013 by ecartsiger Link to comment Share on other sites More sharing options...
unuroboros Posted March 16, 2013 Share Posted March 16, 2013 I don't think you're attaching the script correctly. You should have a quest (flagged start game enabled), with an alias for the player, and the script attached to the alias. It should extend ReferenceAlias; i.e., Scriptname TestActorEquip extends ReferenceAlias Link to comment Share on other sites More sharing options...
ecartsiger Posted March 16, 2013 Author Share Posted March 16, 2013 Thank you, so I don't have to attach script to actor and OnObjectEquipped event will be still called and it actually works. GOOD.The remaining problem is that type casting does not work for me armorChild = testArmor as TestArmorChild string id = "TEST" armorChild.SetID(id) if armorChild.GetID() == id ; getter returns probably empty string but I would expect "TEST"... Debug.Notification(id) endif Link to comment Share on other sites More sharing options...
ecartsiger Posted March 17, 2013 Author Share Posted March 17, 2013 armorChild = testArmor as TestArmorChild ;<--Problem is here, this cast returns None but why? string id = "TEST" armorChild.SetID(id) if armorChild.GetID() == id ; getter returns probably empty string but I would expect "TEST"... Debug.Notification(id) endif I have no idea why type cast from Armor (represented by testArmor) to TestArmorChild returns None.Anyone? Link to comment Share on other sites More sharing options...
unuroboros Posted March 17, 2013 Share Posted March 17, 2013 (edited) Well... the way the tutorial on Cipscis is doing it is a little... unusual. This is the method I was taught, maybe it will help:Make a quest. Check the box for Start Game Enabled.On the Quest Aliases tab, make a Player alias ('Specific Reference', cell any, pick PlayerRef). To click OK to this dialog box, since it will probably be too big for your screen, press Enter in the Alias Name box.In the properties for the alias, add a new script. For example, "PlayerScript". This script will have your OnObjectEquipped event.On the Scripts tab of the quest, add as many scripts as you need. For example, "FunctionScript".Now, in PlayerScript you can call a function in FunctionScript like so:Add a line of code in PlayerScript: FunctionScript Property myFunctions AutoThe important part of this property is that its type (the part before Property) matches exactly the name of the script you are calling.The name (the part after Property) is how you will call upon that script in this script.Finally (very easy to forget this step), open the Properties for the player alias script, and from the drop-down box for the myFunctions property, choose your quest. So, applying that example to your scripts, you will have TestActorEquip (extending ReferenceAlias) attached to the Player alias. Then you'll attach TestArmorChild to the Scripts tab of the quest, and add this Property to that script:TestArmorChild Property armorChild Auto Then, since you can't directly assign its value in the script itself, use the CK to open the properties for TestActorEquip (open the Player alias, right-click TestActorEquip, Edit Properties), and set the value of armorChild; it should match whatever you named the quest. Setting all of this up the first time can be a bit confusing, but after you see how easy and elegant it is, you'll realize how powerful the feature can be. For a large project where you need to break apart your script and call functions in any one of them from any other script, this method is invaluable. I use it in my mod with six different scripts. Edited March 17, 2013 by unuroboros Link to comment Share on other sites More sharing options...
Recommended Posts