OldBrunny Posted January 4, 2016 Share Posted January 4, 2016 While I've done a lot of scripting in Oblivion, I've managed to avoid it for Skyrim so far. But I wanted to create a simple activator to charge any soul gems in the players inventory. After a lot of reading of the tutorials I came up with the following script. Which as a newby to Papyrus looks OK to me, but it will not compile.Can somebody please point out what I've done wrong... ScriptName SJBChargeSoulGems Extends ObjectReference Formlist Property EmptySG AutoFormlist Property FilledSG AutoForm eForm f Event OnActivate(ObjectReference akActionRef) Int n Int i = 6 While (i) i -= 1 e = EmptySG.GetAt(i) n = Game.GetPlayer().GetItemCount(e) If (n) f = FilledSG.GetAt(i) Game.GetPlayer().RemoveItem(e, n, true) Game.GetPlayer().AddItem(f, n, true) EndIf EndWhileEndEvent I've attached the compiler failure output for info: ThanksOldBrunny Link to comment Share on other sites More sharing options...
IsharaMeradin Posted January 4, 2016 Share Posted January 4, 2016 First off, since the latest patch to the Creation Kit the source files (PSC) are inside of a scripts.rar file in your Data folder. The CK needs access to these files in order to compile scripts. Simply extract the scripts.rar folder right where it is. Beyond that, I see some issues with your script. ScriptName SJBChargeSoulGems Extends ObjectReference Formlist Property EmptySG Auto Formlist Property FilledSG Auto Event OnActivate(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() Int i = 6 While (i >= 0) i -= 1 Form e = EmptySG.GetAt(i) Int n = akActionRef.GetItemCount(e) If (n > 0) Form f = FilledSG.GetAt(i) akActionRef.RemoveItem(e, n, true) akActionRef.AddItem(f, n, true) EndIf EndWhile EndIf EndEvent Just a few minor things. 1. If you have no reason to use a variable beyond the level it is in, you can declare its type when you assign the value instead of outside the event. Thus I defined the Form type for e and f when they are being initially assigned a value. This is a non-issue tho. But it is best to be consistent. Either define all variables outside the event, or define them at the highest level necessary to use the value in all locations of the variable. 2. Your WHILE loop would have gone on indefinitely because it was merely checking for the variable to exist with valid data. It wasn't conditioned with anything to stop it. Now when it reaches -1 it will cease. 3. Your IF check for n would allow processing for items that had a 0 count. Since that is a waste of processing power, conditioned it out. 4. Furthermore, there is nothing in place to prevent it from running should another actor somehow activate the object. Would be odd to have the player's soul gems get charged when another NPC uses the object, so added a condition for that too. Link to comment Share on other sites More sharing options...
OldBrunny Posted January 4, 2016 Author Share Posted January 4, 2016 Thank you. I did have the check in for player being the activator but kept getting an error that I could not cast an Object Ref as an Actor, so took it out...Anyway the issue was the lack of the full source scripts. Extracted as you suggested, and then extracted the SKSE scripts again...It compiled.... Link to comment Share on other sites More sharing options...
Recommended Posts