Jump to content

Photo

Scripting help


  • Please log in to reply
24 replies to this topic

#1
OminousVoice

OminousVoice

    Enthusiast

  • Members
  • PipPip
  • 227 posts
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.

#2
Cipscis

Cipscis

    Scripter

  • Premium Member
  • 1,275 posts
That looks fine, does it compile? Have you associated your perk with the property "ThunderPerk"?

Cipscis

#3
OminousVoice

OminousVoice

    Enthusiast

  • Members
  • PipPip
  • 227 posts
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 by OminousVoice, 13 February 2012 - 06:34 AM.


#4
OminousVoice

OminousVoice

    Enthusiast

  • Members
  • PipPip
  • 227 posts
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 by OminousVoice, 13 February 2012 - 07:19 AM.


#5
Cipscis

Cipscis

    Scripter

  • Premium Member
  • 1,275 posts
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
EndEvent
Note 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

#6
OminousVoice

OminousVoice

    Enthusiast

  • Members
  • PipPip
  • 227 posts
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.

#7
Cipscis

Cipscis

    Scripter

  • Premium Member
  • 1,275 posts
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

#8
Stravides

Stravides

    Stranger

  • Members
  • Pip
  • 7 posts

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 managed to do this by using an event of OnInit :) try that

#9
OminousVoice

OminousVoice

    Enthusiast

  • Members
  • PipPip
  • 227 posts

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?

#10
OminousVoice

OminousVoice

    Enthusiast

  • Members
  • PipPip
  • 227 posts

I managed to do this by using an event of OnInit :) try that


OnInit didn't work for me.




Page loaded in: 1.117 seconds