A few Papyrus Questions incl problem with IsRead()

Post » Sun Mar 23, 2014 5:18 am

Hey folks,

I have a few questions about Papyrus, as I am somewhat of a Papyrus noob.

I am writing a script which will, when the player reads a particular book (recipe) they will automatically learn a number of ingredient's specific effects.

I have this working overall (learning the effects), however I am trying to add to the script a condition based upon if the book has already been read.

The problem is that the IsRead() function is causing the script to not compile. The error is:

IsRead is not a function or does not exist

My current script is as follows:

Scriptname GBobMagicItemLearnIngredient extends ObjectReference  Ingredient Property Herb1 Auto Ingredient Property Herb2 Auto Ingredient Property Herb3 Auto Int Property EffectNum1 AutoInt Property EffectNum2 AutoInt Property EffectNum3 AutoMessage Property LearnMsg1 AutoBook Property CurrentBook Auto <---- do I have this correct?Event OnRead()	If CurrentBook.IsRead() <---- where the compile error is		Debug.Notification("TEST - You have already read this book.")	Else		Herb1.LearnEffect(EffectNum1)		Herb2.LearnEffect(EffectNum2)		Herb3.LearnEffect(EffectNum3)		Debug.Notification("TEST - Ingredient effect learned... ")		LearnMsg1.Show()	EndIfendEvent

For my second question, how do I test for if a property is empty or not? For example, if my 3rd ingredient "Herb3" has not been defined, I would like to skip the Herb3.LearnEffect(EffectNum3) line. The script works as is with this, but it does spam the papyrus log with an error. I want to do something like:

If Herb3 == ""

; do nothing

Else

Herb3.LearnEffect(EffectNum3)

EndIf

But, this doesn't work. I am not that experienced with Papyrus.

For my final question, rather than using Debug.Notification to display simple messages to the player, I am attempting to use the normal Message system. I've created a Message that can be passed as a property. The message is along the lines of "Ingredient effect learned...". I would like to include the name of the effect, or the name of the ingredient in order to be more specific.

Do I have to create a specific Message for each possibility - or can I dynamically alter the message (like you can insert a number)?

Thanks in advance for any help!

User avatar
Lauren Graves
 
Posts: 3343
Joined: Fri Aug 04, 2006 6:03 pm

Post » Sun Mar 23, 2014 9:59 am

1. http://www.creationkit.com/IsRead_-_Book is an SKSE function, so you need to install SKSE.

You don't need the CurrentBook property, if you mean to call the IsRead function on the book that the script is attached to. You can simply call:

If(Self.IsRead())...EndIf;orIf(IsRead())...EndIf

2. You could do this:

If(Herb3 != None)  Herb3.LearnEffect(EffectNum3)EndIf;orIf(Herb3)  Herb3.LearnEffect(EffectNum3)EndIf

The way you were doing it would work if Herb3 was a variable/property of the type String, but that is not the case.

3. http://www.creationkit.com/Text_Replacement the relevant wiki article.

I've only replaced numbers in MESG forms, but I think you could have one message that is set to be a notification and contains the necessary tag for text replacement. Said tag would then refer to an http://www.creationkit.com/Quest_Alias_Tab#Reference_Alias_data: in a quest and that alias would in turn use another MESG form as its Display Name. You could then modify the Display Name (and thus the content of the notification) by using SKSE's http://www.creationkit.com/SetName_-_Form function on the MESG form used for the Display Name.

User avatar
Jessica White
 
Posts: 3419
Joined: Sun Aug 20, 2006 5:03 am

Post » Sun Mar 23, 2014 11:29 am

Thanks for your help!

My main problem indeed was a doh! type of error. I had considered that it was a SKSE function, but mis-read the wiki. I will forego this aspect of the script as I am not familiar with coding for SKSE and do not want to (at least not yet) require it for my Mod.

Your other advice was also exactly what I was looking for. I have not yet adjusted my Messages to be dynamic (not sure exactly what I really want to accomplish) but you've provided some thoughts to experiment with.

Again, thanks for your help!

User avatar
Kate Murrell
 
Posts: 3537
Joined: Mon Oct 16, 2006 4:02 am


Return to V - Skyrim