using the AddSpell function in a perk

Post » Tue Jun 19, 2012 11:26 am

This seems like it should be so simple... but I'm stumped.
I'm trying to add a spell to the player's spellbook once they take a particular perk. I created the following script:

Scriptname mystyAddSpell extends Perk
{Adds a spell to the player's spellbook}

SPELL Property learnedSpell Auto

Game.GetPlayer().AddSpell(learnedSpell)

and assigned the property to the spell I want to the player to learn. However, the script does not compile and I don't understand the error message:
no viable alternative at input '.'

From what I can tell, it doesn't like the Game.GetPlayer() bit. I tried adding an actor property to use as a reference instead, but that had errors as well and wouldn't let me assign the property value. What gives?
User avatar
Teghan Harris
 
Posts: 3370
Joined: Mon Mar 05, 2007 1:31 pm

Post » Tue Jun 19, 2012 4:03 am

i think you need to have an event in order for that action to trigger
User avatar
lexy
 
Posts: 3439
Joined: Tue Jul 11, 2006 6:37 pm

Post » Mon Jun 18, 2012 10:59 pm

hmmm... perk scripts don't have any events
User avatar
Damned_Queen
 
Posts: 3425
Joined: Fri Apr 20, 2007 5:18 pm

Post » Mon Jun 18, 2012 11:17 pm

Scripts extending http://www.creationkit.com/Perk_Script will have all native events used for http://www.creationkit.com/Form_Script and "all types" (like http://www.creationkit.com/OnInit) called on them, but I don't think that's what you'd want to use.

Amethyst Deceiver is correct, however, in that any non-declarative code can only exist within functions (including events, which are just functions that can't have a return value), and you need a native event as an entry point for any script to run.

What I think you should do instead is add an "Ability" type perk entry to your perk that adds a scripted ability that runs your code when it is first applied.

Cipscis
User avatar
Everardo Montano
 
Posts: 3373
Joined: Mon Dec 03, 2007 4:23 am

Post » Tue Jun 19, 2012 1:24 am

Cipscis, thank you so much! The ability worked :)
User avatar
Racheal Robertson
 
Posts: 3370
Joined: Thu Aug 16, 2007 6:03 pm

Post » Mon Jun 18, 2012 10:46 pm

Excellent, glad to hear it :)

Cipscis
User avatar
Mario Alcantar
 
Posts: 3416
Joined: Sat Aug 18, 2007 8:26 am


Return to V - Skyrim