OminousVoice Posted February 12, 2012 Share Posted February 12, 2012 I'm trying to write a script for a book so that it grants a perk when you read it. Now, I'm an utter noob when it comes to scripting, so I need all the help I can get. Here's what I have. What am I doing wrong? Scriptname AddThunderPerk extends ObjectReference SPELL Property ThunderReward Auto Perk property ThunderPerk auto Event OnRead() if akActor== Game.GetPlayer() && Game.GetPlayer().HasPerk(ThunderPerk) == 0 Game.GetPlayer().AddPerk(ThunderPerk) Debug.Trace("Heart of Thunder added") endif EndEvent Any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
Cipscis Posted February 13, 2012 Share Posted February 13, 2012 That looks fine, does it compile? Have you associated your perk with the property "ThunderPerk"? Cipscis Link to comment Share on other sites More sharing options...
OminousVoice Posted February 13, 2012 Author Share Posted February 13, 2012 (edited) The compile fails. The compiler output tells me that the variable akActor is undefined.As for asscociating my perk, I think that's what I'm doing with the first two lines, though I'm not entirely sure. I've had a look at the wiki but that's a lot of info to digest. [Edit] I've figured out associating my perk. It's just defining akActor now. Edited February 13, 2012 by OminousVoice Link to comment Share on other sites More sharing options...
OminousVoice Posted February 13, 2012 Author Share Posted February 13, 2012 (edited) Ok, I added an actor property and the script compiles, however in-game it doesn't have the desired effect. Do I need to add anything? Scriptname AddThunderPerk extends ObjectReference Actor property akActor auto Perk property ThunderPerk auto Event OnRead() if akActor== Game.GetPlayer() && Game.GetPlayer().HasPerk(ThunderPerk) == 0 Game.GetPlayer().AddPerk(ThunderPerk) Debug.Trace("Heart of Thunder added") endif EndEvent Edited February 13, 2012 by OminousVoice Link to comment Share on other sites More sharing options...
Cipscis Posted February 13, 2012 Share Posted February 13, 2012 Oh, of course! You were treating akActor as though OnRead has such a parameter that lets you use the actor doing the reading, but this event will only run when the player reads a book. Because your akActor property is never set, it will default to None, and your condition of "if akActor == Game.GetPlayer()" can never be true. This should work:Scriptname AddThunderPerk extends ObjectReference Perk property ThunderPerk auto Event OnRead() if Game.GetPlayer().HasPerk(ThunderPerk) == false Game.GetPlayer().AddPerk(ThunderPerk) Debug.Trace("Heart of Thunder added") endif EndEventNote that I changed "== 0" to "== false". We have proper boolean types in Skyrim, so using "== 1" or "== 0" is now semantically incorrect, even if the automatic cast will make it work. If nothing else, this is something you should be aware of. Cipscis Link to comment Share on other sites More sharing options...
OminousVoice Posted February 13, 2012 Author Share Posted February 13, 2012 Your revisions make sense and the script compiles fine, however it has no effect in game. Something seems to be missing, a reference or something. I'm pretty much stumped. Link to comment Share on other sites More sharing options...
Cipscis Posted February 13, 2012 Share Posted February 13, 2012 Is that no effect including no sign of the debug message in the logs? Have you set up your property in the editor correctly? Cipscis Link to comment Share on other sites More sharing options...
Stravides Posted February 14, 2012 Share Posted February 14, 2012 Is that no effect including no sign of the debug message in the logs? Have you set up your property in the editor correctly? CipscisI managed to do this by using an event of OnInit :) try that Link to comment Share on other sites More sharing options...
OminousVoice Posted February 14, 2012 Author Share Posted February 14, 2012 Is that no effect including no sign of the debug message in the logs? Have you set up your property in the editor correctly? Cipscis I picked my perk from the dropdown box when editing the property. I assume that's how it's supposed to work, but evidentally it's not. How would I go about defining the property in the script itself? Link to comment Share on other sites More sharing options...
OminousVoice Posted February 15, 2012 Author Share Posted February 15, 2012 I managed to do this by using an event of OnInit :) try that OnInit didn't work for me. Link to comment Share on other sites More sharing options...
Recommended Posts